Created
April 5, 2015 12:12
-
-
Save tomcha/51ec8c9de6df8063450d to your computer and use it in GitHub Desktop.
1-22
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #define N 10 | |
| #define MAXSTRINGS 100 | |
| int ggetline(char str[]); | |
| void cleararray(char str[], int n); | |
| int main(){ | |
| char str[MAXSTRINGS]; | |
| char newstr[MAXSTRINGS]; | |
| cleararray(str, MAXSTRINGS); | |
| cleararray(newstr, MAXSTRINGS); | |
| int charno = ggetline(str); | |
| int i = 0, j = 0; | |
| int k; | |
| for(;i < N; i++){ | |
| newstr[i] = str[i]; | |
| if(!(str[i] == ' ' || str[i] == '\t' || str[i] == '\n')){ | |
| k = i; | |
| } | |
| } | |
| // printf("k:%d\n", k); | |
| // printf("i:%d\n", i); | |
| // printf("cn:%d\n", charno); | |
| if( charno > N ){ | |
| j = ++k; | |
| newstr[k++] = '\n'; | |
| for(;j < charno; k++, j++ ){ | |
| newstr[k] = str[j]; | |
| } | |
| } | |
| printf("%s", newstr); | |
| } | |
| int ggetline(char str[]){ | |
| int c; | |
| int i = 0; | |
| while((c = getchar()) != EOF && i < MAXSTRINGS - 1){ | |
| str[i++] = c; | |
| } | |
| return i; | |
| } | |
| void cleararray(char str[], int charno){ | |
| for(int i = 0; i < charno; i++){ | |
| str[i] = '\0'; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment