I'm having the worst time understanding strings. For instance, if I want to read from a file "029894 23874 27695784 39089058340" then all I have to do is set up some integer pointers like so:
1 2 3 4 5 6 7 8
int *cl, column1, etc....;
c1 = (int*) malloc(N*sizeof(int));
etc....
for (i=0; i < N + 1; i++){ // If I have lots of rows of integers to read in.
fscanf(FILETHINGYGOESHERE, "%d %d %d %d", &column1, etc....);
c1[i] = column1;
etc....}
Pretty simple to recall this info for whatever reason. Even if I have doubles to consider, it's straight forward. But dang if I know how to deal with strings the same way! Because if I set it up this way, the computer has a seizure:
1 2 3 4 5 6 7 8
char *cl, column1, etc....;
c1 = (char*) malloc(N*sizeof(char));
etc....
for (i=0; i < N + 1; i++){
fscanf(FILETHINGYGOESHERE, "%c %c %c %c", &column1, etc....);
c1[i] = column1;
etc....}
Every example I read out there with strings, of course, hard wires the string into the code only to break the entire line into individual elements: "Hello world" becomes 12 different arrays, counting the "\0" string at the end. I don't want that. I don't even want the read in just to echo it back out on my screen. I want to be able to hold this data in memory for whatever I want - particularly for manipulation purposes. Surely there is a way to take "Hello" and "world" as two different arrays: c1[0] = Hello, c2[0] = world. So, how do I accomplish this with strings in C++ (not C++11 or C# or any other C, except maybe C itself)? First one to give me the right answer gets one Monopoly-money Dollar.
Conversion specifiers c
Matches a sequence of characters whose length is specified by the
maximum field width (default 1); no terminating null byte is added.