#include <stdio.h>
#include <stdlib.h>
int main() {
char c;
int count;
char arr[50];
c = getchar();
count = 0;
while (c != EOF) {
arr[count] = c;
++count;
}
return (EXIT_SUCCESS);
}
cmust be int. getchar () returns an int to distinguish between a valid character and EOF- Read symbol
- Compare this symbol with EOF: if different transition to 7
- Put this character in an array
arr, elementcount - Prepare a βdifferentβ character in the next element of the array
- Check the character read in 1. for EOF
You need to read different characters in a loop each time. (3., 4., 5.)
, , . (4).
:
#include <stdio.h>
#include <stdlib.h>
int main() {
int c;
int count;
char arr[50];
c = getchar();
count = 0;
while ((count < 50) && (c != EOF)) {
arr[count] = c;
++count;
c = getchar();
}
return (EXIT_SUCCESS);
}
, , - , ? , :
for (c=0; c<count; c++) {
putchar(c);
}
putchar('\n');
return EXIT_SUCCESS;
: printf(). , arr : , () 0 (NUL). NUL .
NUL arr, 50 , 49 ( NUL) NUL .
arr[count] = 0;