I am using DevC++ and have saved it as a C file. I keep getting an error [Error] Id returned 1 exit status. It wont compile. I am learning and am stumped. I also have this other error that states. undefined reference to 'If', so do I then define it with a variable? If you can inform me on this that would be awesome.
/*Program: Coder.c
*Usage: Coder [filename] [action]
where filename = filename for/with coded data
where action = D for decade anything else for
coding
........................................................../
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int encode_charactoer( int ch, int val );
int decode_character( int ch, int val );
int main( int argc, char argv[])
{
FILE fh; /file handle/
int rv = 1; /return value/
int ch =0; /variable to hold a character/
unsigned int ctr = 0; /counter/
int val = 5; /value to code with/
char buffer[257]; /buffer/
if( argc != 3 )
{
printf("\nError: Wrong number of parameters...");
printf("\n\nUsage:\n %s filename action", argv[0]);
printf("\n\n Where:");
printf("\n filename = name of file to code or decode");
printf("\n action = D for decode or C for encode\n\n");
rv = -1; /*set return error value*/
}
else
if ((argv[2][0] == 'D') || (argv [2][0] == 'd' )) /*to decode*/
{
fh = fopen(argv[1], "r"); /*open the file */
if( fh <= 0 ) /*check for error */
{
printf( "\n\nError opening file..." );
rv = -2; /*set return error value*/
}
else
{
ch = getc( fh ); /*get a character*/
while( !feof( fh )) /*check for end of file*/
{
ch = decode_character( ch, val );
putchar(ch); /*write the character to screen*/
ch = getc( fh);
}
fclose(fh);
printf("\n\nFile decoded to screen.\n" );
}
}
else /assume coding to file./
{
fh = fopen(argv[1], "w");
if ( fh <= 0 )
{
printf("\n\nError creating file...");
rv = -3; /*set return value*/
}
else
{
printf("\n\nEnter text to be coded. ");
printf("Enter a blank line to end.\n\n");
while( gets(buffer) != NULL )
{
If( buffer[0] == 0 );
break;
for( ctr = 0; ctr < strlen(buffer); ctr++)
{
ch = encode_character( buffer[ctr], val );
ch = fputc(ch, fh); /*Write the character to file*/
}
}
printf("*\nFile encoded to file.\n");
fclose(fh);
}
}
return (rv);
}
int encode_character( int ch, int val )
{
ch = ch + val;
return (ch);
}
int decode_character( int ch, int val )
{
ch = ch - val;
return (ch);
}
The problem is here:
That
If
with a capital letter is not the same asif
with small letters. So the compiler thinks you're calling a function namedIf
. (The semicolon on the end would be incorrect if this were an if-statement and not a function call.)The linker complains because it tries to find this function called
If
(capital letter) but you didn't define it anywhere.Depending on the compiler flags, you may also get a warning that you are trying to use a function that wasn't declared, but this is technically legal (in some cases.)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
You are right. Wow really silly of me. It was in my face. Thanks it executed perfectly.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit