Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Help With Error In C Program (http://www.go4expert.com/forums/help-error-c-program-t18504/)

fob500 13Jul2009 01:18

Help With Error In C Program
 
Hi i have just started to read 'beginig unix programming' .Here is a sample code given in the book which I'm trying to run ..

Code:

#include  <unistd.h>
#include  <sys/stat.h>
#include  <fcntl.h>
#include  <stdlib.h>
#include<stdio.h>
int main()
{
    char c;
    int in, out;
    in = open(“file.in”, O_RDONLY);
    out = open(“file.out”, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);
    while(read(in,&c,1) == 1)
        write(out,&c,1);
return 0;
 
}

---------------------------------------------------------------------------------------------------
when i try to compile it the following errors are being displayed..

gcc -o 1 1.c
1.c: In function ‘main’:
1.c:10: error: stray ‘\342’ in program
1.c:10: error: stray ‘\200’ in program
1.c:10: error: stray ‘\234’ in program
1.c:10: error: ‘file’ undeclared (first use in this function)
1.c:10: error: (Each undeclared identifier is reported only once
1.c:10: error: for each function it appears in.)
1.c:10: error: stray ‘\342’ in program
1.c:10: error: stray ‘\200’ in program
1.c:10: error: stray ‘\235’ in program
1.c:11: error: stray ‘\342’ in program
1.c:11: error: stray ‘\200’ in program
1.c:11: error: stray ‘\234’ in program
1.c:11: error: stray ‘\342’ in program
1.c:11: error: stray ‘\200’ in program
1.c:11: error: stray ‘\235’ in program
----------------------------------------------------------------
can sum 1 tell whatz going on.Im running this program fron Desktop where i create the file.in which is being copied to file.out in this program.I'm using fedora 10 and I.m writing this program in Gedit text editor.Thanx in advance

xpi0t0s 13Jul2009 15:44

Re: Help With Error In C Program
 
You're using the wrong quotes - use the straight ones instead: ".
The compiler doesn't understand the angle quotes.
Not sure what the other two characters are. It complains about \342, \200, \234, \235; two of these will be the quotes but I don't know what the other two are. Use od -x -c 1.c to display the source code and this will help you identify the other wrong characters.

fob500 13Jul2009 16:11

Re: Help With Error In C Program
 
Quote:

Originally Posted by xpi0t0s (Post 52387)
You're using the wrong quotes - use the straight ones instead: ".
The compiler doesn't understand the angle quotes.
Not sure what the other two characters are. It complains about \342, \200, \234, \235; two of these will be the quotes but I don't know what the other two are. Use od -x -c 1.c to display the source code and this will help you identify the other wrong characters.

K just changed the quotes now the program is running and I'm getting the desired output.But could you please tell me about od -x -c 1.c.Could you be more specific on how to use this command and what it does.

xpi0t0s 13Jul2009 16:56

Re: Help With Error In C Program
 
Try "man od". Or Google it.

fob500 13Jul2009 17:21

Re: Help With Error In C Program
 
Quote:

Originally Posted by xpi0t0s (Post 52409)
Try "man od". Or Google it.


Well Thanks :happy:


All times are GMT +5.5. The time now is 15:31.