1、
#include <stdio.h> #define NUMBER 10 int main(void) { int i; char s[NUMBER][128]; for(i = 0; i < NUMBER; i++) { printf("s[%d] = ", i); scanf("%s", s[i]); if(strcmp(s[i], "$$$$$") == 0) break; } puts(" ================================"); for(i = 0; i < NUMBER; i++) { if(strcmp(s[i], "$$$$$") == 0) break; else printf("s[%d] = "%s" ", i, s[i]); } return 0; }
2、
#include <stdio.h> #define NUMBER 10 int main(void) { int i, j = 0; char s[NUMBER][128]; for(i = 0; i < NUMBER; i++) { printf("s[%d] = ", i); scanf("%s", s[i]); if(strcmp(s[i], "$$$$$") == 0) break; j++; } puts(" ====================="); for(i = 0; i < j; i++) { printf("s[%d] = "%s" ", i, s[i]); } return 0; }