I'm trying to sort a lot of data in a text file so I'm trying to create a function to make things easier. In my function I'm trying to store values in a string array like this: example[j]="word". In my function I increment j because the function is being called in a loop in main so the next spot in example[] will have to be used. However when I try to print the full array it only prints the last word entered to example[]. When I use the same code in main instead of calling the function the full array prints. What's going on?
PS sorry I didn't post my code its kind of all over the place right now since I'm testing but if you need to see it to help I can post it
that didn't work; I assume you meant to put static in front of j in the function inputs because that's where j is. There is no for loop except for when I'm trying to print the array. I'm using a while loop to read the file data and in that loop I'm calling the function. Like I said when I do it without the function it works but that's pretty cumbersome. Anyways, I'll do some research the array pointer u mentioned, thanks.
If you're using C++ rather than C, the array's type should be std::vector<std::string>, Especially given that you're reading data from a file, how would you know how big the array shoudl be ahead of time?
In my function I'm trying to store values in a string array ... I'm using a while loop to read the file data and in that loop I'm calling the function.