Why not?
The next part of the problem involved taking the newly "parsed" array of words, sorting them in alphabetical order and then printing them.
//prototypes
void ParseSentence(char...
Type: Posts; User: w2look
Why not?
The next part of the problem involved taking the newly "parsed" array of words, sorting them in alphabetical order and then printing them.
//prototypes
void ParseSentence(char...
Actually, I think I got it!
Changed the code in the for loop to:
for(i = 1; i < size - 1; i++)
{
words[i] = strtok(NULL, " .,;");
I see what you're saying, I have since moved on to the next part of this problem and it is causing me problems. While I am getting the printed output I desired, the words are not being stored in the...
OK, this time I think I've got it.
void ParseSentence(char *ptrA)
{
char temp[80];
int i;
strcpy(temp, ptrA);
looks like I spoke too soon.
no more seg fault, but not printing past the first word
hmm?
I don't know what I was thinking, I didn't need a while loop at all.
If I was smarter and read your advice thoroughly, I would have saved myself some time.
i.e. "You need to print until you run...
I'm not quite sure where you got the # 40 from. The default size of the buffer for user input is 80 chars. But what you suggest makes sense. I guess I should be using a while loop instead of a for...
I thought that there may be a possibility of another part of my program causing the problem
so I put everything regarding this function into it's own program to try and isolate the problem.
Here is...
Tried changing it to this, but same result.
void ParseSentence(char *ptrA)
{
char temp[80];
char *words[80];
strcpy(temp, ptrA);
Do I use an if statement for that?
like
if (character == NULL)
break;
Should I be copying the char array being passed to the function into a temp array before using strtok?
If so, how do I do that? I'm kinda new to C.
OK, I changed the code to the following.
Still getting the same result.
//prototype *was wrong in initial post*
void ParseSentence(char *ptrA);
//call in main
ParseSentence(Buffer3);
I am writing a function to parse a sentence and print each separate word on a new line.
For some reason, I keep getting a Seg fault. Can anyone please tell me what I am doing wrong?
It is...