i have a c project and i have serious problem , i want to open file and replace line number nb (nb is an int) with "*" . this is my code could some one help me please ? it show me the word i want to replace that's mean that the pointer is pointing on the wanted line but nothing happen .help me please
#include <stdio.h>
int main( void )
{
    FILE * f;
    char ch[1024];
    int i, nb;
    i = 0;
    scanf( "%d", &nb ) ;
    f = fopen( "dict.txt", "r+t" );
    while( i < nb )
     {
        fscanf( f, "%s", ch ) ;
        i++;
     }
    printf( "%s", ch );
    fprintf( f, "%s", "****" );
    fclose( f );
}
 
                        
You've opened the file for reading and writing. According to the MSDN man page for
fopen(I am assuming from ther+tmode on the file that you are using Visual Studio):Some other things to keep in mind:
fscanfreads a string with%s, it reads only one word at a time, not a whole line. It is easier to read whole lines of input withfgetsthan withfscanf.fprintf(f, "%s", "****")will only replace the first four bytes in the line.Try something like this instead: