Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how can i remove space between ^I and letters

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 остается 
неизменными и возвращается нулевой указатель. 

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading