hafez1
جمعه 05 آبان 1391, 12:51 عصر
یه برنامه هست که درباره strtok گرفتم از اینترنت.بد خودم یکم تغییرش دادم.به برنامه من ارور می گیره.
این برنامه ایه که از اینترنت گرفتم:
#include <iostream.h>
#include<conio.h>
#include <string.h> // prototype for strtok
int main()
{ clrscr();
char sentence[] = "This is a sentence with 7 tokens";
char *tokenPtr;
cout << "The string to be tokenized is:\n" << sentence
<< "\n\nThe tokens are:\n\n";
// begin tokenization of sentence
tokenPtr = strtok( sentence, " " );
// continue tokenizing sentence until tokenPtr becomes NULL
while ( tokenPtr != NULL )
{
cout << tokenPtr<<”\n”;
tokenPtr = strtok( NULL, “ ” ); // get next token
} // end while
cout << "\nAfter strtok, sentence = " << sentence << endl;
getch();
return 0; // indicates successful termination
} // end main
توی این برنامه رشته ای که اعضاشو جدا می کنه یه رشته ثابته من می خام رشتم دلخواه باشه ینی خودم وارد کنم.
من این جوری برناممو نوشتم:
#include <iostream> #include<conio.h> #include <string.h> // prototype for strtok using namespace std; int main() { string s; cin>>s; char sentence[] = s; char *tokenPtr; cout << "The string to be tokenized is:\n" << sentence << "\n\nThe tokens are:\n\n"; tokenPtr = strtok( sentence, "+" ); while ( tokenPtr != NULL ) { cout << tokenPtr<<"\n"; tokenPtr = strtok( NULL, "+" ); } getch(); return 0; }
اشکالش چیه؟؟؟؟
این برنامه ایه که از اینترنت گرفتم:
#include <iostream.h>
#include<conio.h>
#include <string.h> // prototype for strtok
int main()
{ clrscr();
char sentence[] = "This is a sentence with 7 tokens";
char *tokenPtr;
cout << "The string to be tokenized is:\n" << sentence
<< "\n\nThe tokens are:\n\n";
// begin tokenization of sentence
tokenPtr = strtok( sentence, " " );
// continue tokenizing sentence until tokenPtr becomes NULL
while ( tokenPtr != NULL )
{
cout << tokenPtr<<”\n”;
tokenPtr = strtok( NULL, “ ” ); // get next token
} // end while
cout << "\nAfter strtok, sentence = " << sentence << endl;
getch();
return 0; // indicates successful termination
} // end main
توی این برنامه رشته ای که اعضاشو جدا می کنه یه رشته ثابته من می خام رشتم دلخواه باشه ینی خودم وارد کنم.
من این جوری برناممو نوشتم:
#include <iostream> #include<conio.h> #include <string.h> // prototype for strtok using namespace std; int main() { string s; cin>>s; char sentence[] = s; char *tokenPtr; cout << "The string to be tokenized is:\n" << sentence << "\n\nThe tokens are:\n\n"; tokenPtr = strtok( sentence, "+" ); while ( tokenPtr != NULL ) { cout << tokenPtr<<"\n"; tokenPtr = strtok( NULL, "+" ); } getch(); return 0; }
اشکالش چیه؟؟؟؟