Hello>>>
How are you all?
I need a quick help with my assignment... it is in C not in C++... So, Could you help me?
I don't know what to do!!
the question is:
Write a program that reads a data file containing a C program and writes it to another file removing all comments.
the rubbish answer that i made :( :
#include <stdio.h>
#include <string.h>
void main ()
{
FILE *ptr;
FILE *ptr2;
char *com = { "*/" };
char str[500], str2[500];
if( ( ptr = fopen( "program.dat", "w" ) ) == NULL )
printf( "\n Failed to open the file" );
else
{
printf( "\nEnter a C program:" );
fprintf( ptr, "%s", str );
}
strcpy( str2, str );
if( ( ptr = fopen( "program.dat", "r" ) ) == NULL )
printf( "\n Failed to open the file" );
else
{
while( !feof( ptr ) )
{
for( int i=0; str[i]!= NULL; i++ )
if( ( ptr2 = fopen( "newfile.dat", "w+" ) ) == NULL )
printf( "\n Failed to open the file" );
else
{
if( str[i]=='/' && str[i+1]=='*' )
{
com = strstr( str, com );
while( com != NULL )
{
com = strstr( com+1, str );
}
}
else
fprintf( ptr2, "%c", str2[i] );
}
}
}
}