Hi there is there a way to determine end of the standart input stream and end of a file? I tried to do it like EOF but it doesn't work moreover, as an output it produces weird things.
Here is my code:
Code:
#include <stdio.h>
int strip(char *arr)
{
int i=0;
while (1){
char c =getchar();
if (c!=' '&& c!= '\t')
{
arr[i]=c;
i+=1;
printf ("%c\n", c);
}
else if (c == EOF){
printf ("4\n");
break;
}
}
while(i>0)
{
printf ("%c", arr[i]);
i-=1;
}
return 0;
}
int main()
{
char arr[100];
printf ("Enter some string: \n");
strip(arr);
}
what I wanted is to print standart input without spaces utill it gets to the end of the string. and if I am runing it like ./myprog <text.txt
where text.txt contains Hello there .. the output is:
ÿ
ÿ
ÿ
ÿ
ÿ
ÿ
ÿ
ÿ
ÿ
Segmentation fault
Thanks in advance!