May 13'24

Exercise

Write a program that prompts the user for a sentence (again, pick a maximum length), and prints each word on its own line.

May 13'24

#define __STDC_WANT_LIB_EXT1__ 1 // Active C11 extended functions (this case is gets_s)

  1. include

int slen(const char *); // I don't want to include whole string lib just for get size

int main(void) {

 char s[500];
 printf("%s","Enter a sentence: ");
 if(!gets_s(s,500)) {
   puts("Error!");
   getchar();
   return 0;
 }
 for(int i=0;i

}

int slen(const char *s) {

 int i;
 for(i=0;s[i]!=0;i++);
 return i;

}

00