Here is the code: I hope not knowing exactly how to post code will not be a hinderance.....
Code:
#include <iostream>
#include <string.h>
using namespace std;
int get_a_string(char *buffer, char *s, int start);
char strs[10][100];
int main() {
int i;
int n;
int pos = 0;
char buffer[200];
cout << "Enter strings, separated by commas,";
cout << endl << "and press ENTER: ";
cin.getline(buffer, 199);
for (i = 0; i < 10; i++) {
pos = get_a_string(buffer, strs[i], pos);
if (pos == -1)
break;
}
if (i == 11)
n = 10;
else
n = i;
cout << n << " strings were read." << endl;
for (int i = 0; i < n; i++)
cout << strs[i] << endl;
system ("PAUSE");
return 0;
}
//Get-a-string function.
//Starting at position "start," read next substring
//from buffer into target string s.
//Return position of first unread character;
//return -1 if there are no characters to read.
//
int get_a_string(char *buffer, char *dest, int pos) {
int i = pos, j = 0;
//"Consume" initial comma and blank space(s).
while (buffer[i] == ',' || buffer[i] == ' ')
i++;
//Return -1 if at end of buffer.
if (buffer[i] == '\0')
return -1;
//Read characters into target string, until
//comma or end-of-string encountered.
while (buffer[i] != ',' && buffer[i] != '\0')
dest[j++] = buffer[i++];
//Terminate target string and return position
//of first unread character.
main(dest[j] = '\0')
return i;
}
I threw the "system("PAUSE")" in there so I can beat my chest a little when I`m successful --- before the window disappears...typically the compiler doesn`t gag on this line so I wouldn`t think that was it. To satisfy myself I removed it once, recompiled, and got the same message.
I`ve never coded before and this is my first book so you know my level of inproficiency...
Plain