Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
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() ...
  1. #1
    Just Joined!
    Join Date
    Jul 2009
    Location
    India
    Posts
    24

    Post [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

  2. #2
    Banned
    Join Date
    Jul 2009
    Posts
    12
    It does compile perfectly on mine ... I can't really help, though.

  3. #3
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    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?

    ...G4143
    Make mine Arch Linux

  4. #4
    Banned
    Join Date
    Jul 2009
    Posts
    12
    I didn't notice.

  5. #5
    Just Joined!
    Join Date
    Jul 2009
    Location
    India
    Posts
    24
    Quote Originally Posted by gerard4143 View Post
    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?

    ...G4143
    I didn't get it could you be more specific.I have tried changing the quotes " with '..It still gives a warning.When I try to run it doesn't produce the file.out which it should to copy file.in.

  6. #6
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    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

  7. #7
    Banned
    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.

  8. #8
    Just Joined!
    Join Date
    Jul 2009
    Location
    India
    Posts
    24
    Quote Originally Posted by gerard4143 View Post
    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

    I'm using the normal text editor that ships along with Fedora 10.Please tell me if i can give more specific info and how to find it regarding the text editor..Thanx .

  9. #9
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Is that editor Kwrite or Gedit?...G4143
    Make mine Arch Linux

  10. #10
    Just Joined!
    Join Date
    Jul 2009
    Location
    India
    Posts
    24
    Quote Originally Posted by JeffGoldblum View Post
    Yeah, with the quotation marks you have, I get the exact same messages, but it compiles perfectly with the proper quotation marks.
    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'

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...