tags:

views:

120

answers:

3
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
    // int
    char str[40],ch;

    FILE*fp,*fp1,*fp2;

    fp=fopen("ide_input","w");
    fp1=fopen("error_log","w");
    fp2=fopen("lex_output","w");

    if(fp==NULL || fp1==NULL)
    {
        strcpy(str,"file cannot be found");
        fputc(str,fp1);
    }

    while(1)
    {
        ch=fgetc(fp);
        if(ch==EOF)
            break;
        else
        {
            if(ch!='/0')
                fputc(ch,fp2);
        }
    }
    fclose(fp);
    fclose(fp1);
    system("pause");
    return 0;
}

This code is giving me an error of "build error .. error 1". May I know why? I am on Windows XP working on dev cpp?

A: 

There are some problems with your code. One thing is that you've written /0 instead of \0, and another one is that you are using fputc to print a string, when you should be using fputs.

I don't know if that is what causes that "Error 1", but you can start by fixing those errors.

EDIT:

I haven't used this particular compiler, but every other compiler I have ever used prints more specific error messages when it finds a en error in the code. Are you sure you can't get anything more specific than "Error 1"?

And if you can't: Does it print more specific error messages in other cases? If it does, then perhaps there is nothing wrong with your program, and the error is caused by something else, such as a full disk?

And another idea: In your original post, there was some problems with the #include lines in the beginning, but someone edited that for you. Perhaps that wasn't a problem just in the post, but there was an error in your original program? Check those lines! (Preprocessor errors can sometimes cause strange error messages.)

Thomas Padron-McCarthy
i did the changes still its saying build error[compiler.exe] error 1
mekasperasky
+1  A: 

fputc() accepts a character and a stream in that order. You're passing it a pointer and a stream.

if(ch!='/0') You're comparing ch (a character) to a multi-character constant (the comparison will always yield "true"),
I think you want if(ch!='\0')

And maybe your compiler does not accept C99 comments (the //int at the top)


Edit

Also you're comparing a char to an int at

ch = fgetc(fp);
if (ch == EOF)
    break;

fgetc() returns an int. I don't think this would cause the compiler to generate an error, but your program wouldn't necessarily run as intended.


Edit2

According to some results from Google, you may want to try and copy your code to a brand new project, with a brand new makefile, and try again.

pmg
i did the chages and still got the same error .want to know what it means ?
mekasperasky
+1  A: 

The errors in the program itself won't cause this "error 1".

Simply googling for dev cpp error 1 returns a lot of similar problems, most have to do with path issues.

Can you pls provide complete output of error message?

Gerd Klima