Reading and parsing lines from a file with fgets and strtok

后端 未结 2 1256
青春惊慌失措
青春惊慌失措 2021-01-13 23:57

I\'m having trouble with a fairly basic bit of code. I need to read each line from the file shown below, split it up into the 3 parts with strtok, and store each part into a

2条回答
  •  广开言路
    2021-01-14 00:24

    You didn't copy out the name, you just put the pointer returned by strtok into your data structure. You are just ending up with a data structure full of identical pointers to the same memory pointed to by buffer. Since the contents of buffer get modified on every pass through the loop, you end up with a bunch of pointers to whatever it was the last time through.

提交回复
热议问题