#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <string.h> int main() { char* limits = " ,-!"; char str[20]; char save_str[10][10]; int len[10]; int i = 0; printf("Full the string\n"); fgets(str, 20, stdin); char* str1 = strtok(str, limits); while (str1 != NULL) { len[i] = strlen(str1); save_str[i][10] = *str1; printf("%s\n", str1, strlen(str1)); str1 = strtok(NULL, limits); i++; } printf("new\n"); for (int j = 0; j < i; j++) { printf("%s\n", save_str[j][len[j]]); } getchar(); getchar(); return 0; } - oneSelect a specific programming language. C and C ++ have different means. - Vlad from Moscow
|
1 answer
To start after a sentence with fgets
fgets(str,20,stdin); write
str[ strcspn( str, "\n" ) ] = '\0'; Instead of this sentence
save_str[i][10] = *str1; write down
strncpy( save_str[i], str1, 10 ); save_str[i][9] = '\0'; And also instead of this sentence
printf("%s\n", str1, strlen(str1)); write either
printf("%d: %s\n", len[i], str1 ); or simply
puts( str1 ); Also this sentence should be corrected.
printf("%s\n",save_str[j][len[j]]); For example,
printf("%s\n",save_str[j]); or
puts( save_str[j] ); - does not help pastebin.com/v7BMEefF - Mark Koval
- @MarkKoval What exactly is the problem this time? - Vlad from Moscow
- i.stack.imgur.com/Xp6UA.png not compiling - Mark Koval
- @MarkKoval Compile errors you can correct yourself. - Vlad from Moscow
- but in which here the error may be (long thought) - Mark Koval
|
