在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
Write a function #include <stdio.h> #define MAX_LINE 1024 void discardnewline(char s[]) { int i; for(i = 0; s[i] != '\0'; i++) { if(s[i] == '\n') s[i] = '\0'; } } int reverse(char s[]) { char ch; int i, j; for(j = 0; s[j] != '\0'; j++) { } --j; for(i = 0; i < j; i++) { ch = s[i]; s[i] = s[j]; s[j] = ch; --j; } return 0; } int getline(char s[], int lim) { int c, i; for(i = 0; i < lim - 1 && (c = getchar()) != EOF && c != '\n'; ++i) { s[i] = c; } if(c == '\n') { s[i++] = c; } s[i] = '\0'; return i; } int main(void) { char line[MAX_LINE]; while(getline(line, sizeof line) > 0) { discardnewline(line); reverse(line); printf("%s\n", line); } return 0; }
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论