Hi everybody.
I'm trying to write the program that will read the file and delete blank spaces ONLY after the text.
here is the text :
serg@serg-PORTEGE-Z835:~$ cat sample.txt
Now is the
here is the the same in hex:
serg@serg-PORTEGE-Z835:~$ od -x sample.txt
0000000 2020 2020 2020 2020 2020 2020 2020 2020
0000020 6f4e 2077 7369 7420 6568 2020 2020 2020
The program that I wrote gives me the result:
serg@serg-PORTEGE-Z835:~$ cat sample.out
Now is th
As you can notice ther is no 'e' at the end,
the hex looks something like this:
0000000 2020 2020 2020 2020 2020 2020 2020 2020
0000020 6f4e 2077 7369 7420 0a68 000a
0000033
So my question is how to achive something like this:
0000000 0909 4e6f 7720 6973 2074 6865 0a09 0954
here is the code of my program:
#include<stdio.h>
#define SIZE 1000
int getLine(char *line, int lim);
int getLine(char *line, int lim) {
int i;
char c;
for(i=0; i<lim-1 && (c=getchar()) !=EOF && c!='\n'; ++i) {
*(line+i) = c;
}
line[++i]='\0';
return i;
}
main() {
int c,i;
char line[SIZE];
c=getLine(line, SIZE);
for(i=c; i>0 && ((line[i]<='!') || (line[i]>='~')); i--){
if (line[i]=='\n') {
line[i]=0;
}
else {
line[i]=0;
c--;
}
/* if ((line[i]<='!') && (line[i]>='~'))
line[i]=0;
else
break;
*/
}
for( i=0; i<c ; i++) {
printf("%c", line[i]);
}
printf("\n\n");
}