Home > Net >  how can i remove space between ^I and letters
how can i remove space between ^I and letters

Time:07-03

how can i remove space between ^I and letters? I do not understand. how can i remove space between ^I and letters?

#include <stdio.h>
#include <stdlib.h>
int main()
{
    char c;
    int z = 1;
    char ll = '\t';
    char cur = '\0';

    FILE* file = fopen("2.txt", "r");
    while ((c = getc(file)) != EOF) {
        if (c == ll)
            printf("^I");
        putc(c, stdout);
    }
    fclose(file);
    return 0;
}

OUTPUT:

 ^I     В случае успеха, 
 ^I     функция возвращает указатель ^I на string. 
 Если конец.
 файла был достигнут и ни один символ 


не был прочитан, содержимое string остается 
неизменными и возвращается нулевой указатель. 

Если происходит ошибка, возвращается нулевой.

CodePudding user response:

If I understand your code correctly, you want to replace '\t' with '^I'.

The problem you have is that you insert '^I' if the character is a tabulation, but still print it. You need to print the character that have been read only if it is not a tabulation, like so :

if (c == ll)
    printf("^I");
else 
  putc(c, stdout);

Also, EOF is an integer type, you need you variable c to be an int

  •  Tags:  
  • c
  • Related