1

I am writing a program in C and I want to count how the number of words in the string by dividing the string by the spaces.

Here is some of my code

  while((temp = strsep(&tempInput, " "))!=NULL)
  {
    tempArguments[number] = temp;
    number++;
    printf("AGAIN\n");
  }
  printf("number: %d",number);

For some reason I get a segmentation fault when the loop terminates. Does anybody have an idea as to what could be causing this?

Jake Gearhart
  • 297
  • 7
  • 21
  • 1
    I think the most important bits here are going to be how `number`, `tempArguments` and `tempInput` are declared and initialized. – Collin Feb 18 '14 at 22:28
  • I don't `tempInput` is the problem here as I assume you are sending that as a char** buffer pointer. Maybe your `tempArguments` array is going out of bounds. – PSeUdocode Feb 18 '14 at 22:38
  • the tempArguments array is of size 80, arbitrarily chosen, and in this case there is one string being put into it. – Jake Gearhart Feb 18 '14 at 23:24

0 Answers0