Sunday, August 2, 2009

Help with C++?

Hello,





I am kinda new to C++ i think i know most of the basics of it, But anyway my question is i am trying to make a program that will read thru a txt file and separate the words in the file. Something like this, say i have these 2 words in a text file (what,are) i make a program that read this and separates the 2 words into 2 diff arrays and then prints them to the screen.But i can't do this what the text in the file goes to the next line.Here is the code i have for the loop that reads the file.





int get(char*buffer,char*s,int pos){


int i=pos, j=0;


while(buffer[i]== ',' || buffer[i] == ' ' || buffer[i]== '\n')


i++;


while(buffer[i] != ','%26amp;%26amp; buffer[i]!= '\0')


s[j++]=buffer[i++];


s[j]= '\0' ;


return i;}


This works fine but can someone please tell me how i can do this so it will work with a newline?





Thank you for anyhelp.

Help with C++?
What do mean "work with newline"?





You don't show how you read the string. It is entirely possible that you used a function that replaces the newline with a null terminator byte.





Show more of your code. While your get() function may seem to work, it has problems.
Reply:Why aren't you using strtok to tokenize the string.


No comments:

Post a Comment