This C programming code is not run properly. Please fix this problem and solve this error. # include # include int main( ) { // Declare the file pointer FILE *filePointer,*filePointer1 ; int n; printf("enter a key for encryption"); scanf("%d",&n); // Declare the variable for the data to be read from file char dataToBeRead[50]; filePointer = fopen("test.txt", "r") ; filePointer1 = fopen("final.txt", "w") ; // Check if this filePointer is null // which maybe if the file does not exist if ( filePointer == NULL ) { printf( "test.txt file failed to open." ) ; } else { printf("The file is now opened.\n") ; // Read the dataToBeRead from the file // using fgets() method while( fgets ( dataToBeRead, 50, filePointer ) != NULL ) { // Print the dataToBeRead printf( "%s" , dataToBeRead ) ; int i; for(i=0;i
This C programming code is not run properly. Please fix this problem and solve this error.
# include <stdio.h>
# include <string.h>
int main( )
{
// Declare the file pointer
FILE *filePointer,*filePointer1 ;
int n;
printf("enter a key for encryption");
scanf("%d",&n);
// Declare the variable for the data to be read from file
char dataToBeRead[50];
filePointer = fopen("test.txt", "r") ;
filePointer1 = fopen("final.txt", "w") ;
// Check if this filePointer is null
// which maybe if the file does not exist
if ( filePointer == NULL )
{
printf( "test.txt file failed to open." ) ;
}
else
{
printf("The file is now opened.\n") ;
// Read the dataToBeRead from the file
// using fgets() method
while( fgets ( dataToBeRead, 50, filePointer ) != NULL )
{
// Print the dataToBeRead
printf( "%s" , dataToBeRead ) ;
int i;
for(i=0;i<strlen(dataToBeRead);i++)
dataToBeRead[i]=(dataToBeRead[i]+n)%26;
fputs(dataToBeWritten, filePointer1) ;
fputs("\n", filePointer1) ;
}
// Closing the file using fclose()
fclose(filePointer) ;
printf("Data successfully read from file GfgTest.c\n");
printf("The file is now closed.") ;
}
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images