How can I split up a string into whitespace-separated fields?



How can I split up a string into whitespace-separated fields?..

Answer / Rajeev Kumar Shukla

To split a string into whitespace-separated fields, you can use the `strtok()` function. Here's an example of splitting a string using `strtok()`:nn```cn#include <stdio.h>n#include <string.h>nnint main() {n char str[] = "This is a sample string";n char* token;nn // Tokenize the string using whitespace delimiters:n token = strtok(str, " ");n while(token != NULL) {n printf("%s
", token);n token = strtok(NULL, " ");n }nreturn 0;n}n```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

hi, which software companys will take,if d candidate's % is jst 55%?

1 Answers  


write an algorithm and a program to count the number of elements in a circularly singly linked list

1 Answers   Ignou,


Write a program which calculate sum of several number and input it into an array. Then, the sum of all the number in the array is calculated.

2 Answers  


what do you mean by defining a variable in our c code?

2 Answers  


write a program to arrange the contents of a 1D array in ascending order

4 Answers  


what is the difference between while and do while?

2 Answers  


What is 'bus error'?

1 Answers  


What is the difference between exit() and _exit() function in c?

1 Answers  


Is it better to use malloc() or calloc()?

1 Answers   Aspire, Infogain,


Explain with the aid of an example why arrays of structures don’t provide an efficient representation when it comes to adding and deleting records internal to the array.

1 Answers  


any "C" function by default returns an a) int value b) float value c) char value d) a & b

1 Answers  


Write a program to swap two numbers without using third variable in c?

1 Answers  


Categories