Results 1 to 10 of 20
Hi i have just started to read 'beginig unix programming' .Here is a sample code given in the book
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include<stdio.h>
int main()
...
- 07-12-2009 #1Just Joined!
- Join Date
- Jul 2009
- Location
- India
- Posts
- 24
[SOLVED] Help With C
Hi i have just started to read 'beginig unix programming' .Here is a sample code given in the book
#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.Thanx in advance
- 07-12-2009 #2Banned
- Join Date
- Jul 2009
- Posts
- 12
It does compile perfectly on mine ... I can't really help, though.
- 07-12-2009 #3
I've seen this before, its the quotes in your program...or what you think are quotes are not really quotes. In my editor this is a quote " in your program this is what your using for quote ”. they look the same but they are not, look at them side by side ”" see how they differ. What are you using you an editor to write your program?
...G4143Make mine Arch Linux
- 07-12-2009 #4Banned
- Join Date
- Jul 2009
- Posts
- 12
I didn't notice.
- 07-12-2009 #5Just Joined!
- Join Date
- Jul 2009
- Location
- India
- Posts
- 24
- 07-12-2009 #6
It's not a single quote, double quote thing. Your editor is using the wrong ascii symbol(s) for double quotes, its using the hex values 0xe2 0x80 instead of 0x22...What editor are you using?...G4143
Make mine Arch Linux
- 07-12-2009 #7Banned
- Join Date
- Jul 2009
- Posts
- 12
Yeah, with the quotation marks you have, I get the exact same messages, but it compiles perfectly with the proper quotation marks.
- 07-12-2009 #8Just Joined!
- Join Date
- Jul 2009
- Location
- India
- Posts
- 24
- 07-12-2009 #9
Is that editor Kwrite or Gedit?...G4143
Make mine Arch Linux
- 07-12-2009 #10Just Joined!
- Join Date
- Jul 2009
- Location
- India
- Posts
- 24
When i put proper quotation mark It compile with no errors but a couple of warnings
------------------------------------------------------------------------------------------------------------
#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;
}
----------------------------------------------------------------------------------------------------------
gcc -o 1 1.c
1.c:10:15: warning: character constant too long for its type
1.c: In function ‘main’:
1.c:10: warning: passing argument 1 of ‘open’ makes pointer from integer without a cast
1.c:11:16: warning: character constant too long for its type
1.c:11: warning: passing argument 1 of ‘open’ makes pointer from integer without a cast
----------------------------------------------------------------------------------------------------------------------------
Still whe i run the program .i dont get the output which is I should,Which is getting a new file.out which copies the contets of 'file.in'



