Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 7th, 2007, 8:52 AM   #1
boraciner
Programmer
 
boraciner's Avatar
 
Join Date: Nov 2005
Location: Turkey
Posts: 93
Rep Power: 3 boraciner is on a distinguished road
Basic Socket Programming Error in Linux.. Pls help

Hi! I don't have experiance in linux C programming. I took a linux socket programming book and tried the first example code but It didn't work. I use these codes.. please help me!
Thanks for your replies

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
int
main(int argc,char **argv) {
    int z;                   /* Status return code */
    int s[2];                /* Pair of sockets */
    /*
      * Create a pair of local sockets:
      */
    z = socketpair(AF_LOCAL,SOCK_STREAM,0,s);
    if ( z == -1 ) {
         fprintf(stderr,
             “%s: socketpair(AF_LOCAL,SOCK_STREAM,0)\n”,
             strerror(errno));
         return 1;           /* Failed */
    }
    /*
      * Report the socket file descriptors returned:
      */
    printf(“s[0] = %d;\n”,s[0]);
    printf(“s[1] = %d;\n”,s[1]);
    system(“netstat --unix -p”);
    return 0;
}


Error Message:

bora.c: In function ‘main’:
bora.c:18: error: stray ‘\342’ in program
bora.c:18: error: stray ‘\200’ in program
bora.c:18: error: stray ‘\234’ in program
bora.c:18: error: expected expression before ‘%’ token
bora.c:18: error: stray ‘\’ in program
bora.c:18: error: stray ‘\342’ in program
bora.c:18: error: stray ‘\200’ in program
bora.c:18: error: stray ‘\235’ in program
bora.c:25: error: stray ‘\342’ in program
bora.c:25: error: stray ‘\200’ in program
bora.c:25: error: stray ‘\234’ in program
bora.c:25: error: expected expression before ‘%’ token
bora.c:25: error: stray ‘\’ in program
bora.c:25: error: stray ‘\342’ in program
bora.c:25: error: stray ‘\200’ in program
bora.c:25: error: stray ‘\235’ in program
bora.c:26: error: stray ‘\342’ in program
bora.c:26: error: stray ‘\200’ in program
bora.c:26: error: stray ‘\234’ in program
bora.c:26: error: expected expression before ‘%’ token
bora.c:26: error: stray ‘\’ in program
bora.c:26: error: stray ‘\342’ in program
bora.c:26: error: stray ‘\200’ in program
bora.c:26: error: stray ‘\235’ in program
bora.c:27: error: stray ‘\342’ in program
bora.c:27: error: stray ‘\200’ in program
bora.c:27: error: stray ‘\234’ in program
bora.c:27: error: ‘netstat’ undeclared (first use in this function)
bora.c:27: error: (Each undeclared identifier is reported only once
bora.c:27: error: for each function it appears in.)
bora.c:27: error: expected ‘)’ before numeric constant
bora.c:27: error: stray ‘\342’ in program
bora.c:27: error: stray ‘\200’ in program
bora.c:27: error: stray ‘\235’ in program



I used this command to compile

 gcc bora.c -o bora `pkg-config --cflags --libs gtk+-2.0`
boraciner is offline   Reply With Quote
Old Sep 7th, 2007, 11:08 AM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
You cannot use quotes of the opening/closing type. Use the ordinary double-quote character, ".
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Sep 8th, 2007, 6:47 AM   #3
boraciner
Programmer
 
boraciner's Avatar
 
Join Date: Nov 2005
Location: Turkey
Posts: 93
Rep Power: 3 boraciner is on a distinguished road
First of all, Thanks for your reply DaWei.
As I see, I didn't use ' character instead of " in my codes. My english isn't very well so, I couldn't understand where I did a mistake. Can you edit for me then I will be able to understand these codes correctly.
boraciner is offline   Reply With Quote
Old Sep 8th, 2007, 6:56 AM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
This: “s[0] = %d;\n” is not the same thing as
this: "s[0] = %d;\n"
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Sep 8th, 2007, 7:40 AM   #5
boraciner
Programmer
 
boraciner's Avatar
 
Join Date: Nov 2005
Location: Turkey
Posts: 93
Rep Power: 3 boraciner is on a distinguished road
ok! I will try '' in a moment. I'll write what terminal displays.
boraciner is offline   Reply With Quote
Old Sep 8th, 2007, 7:50 AM   #6
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Bear in mind that " is a single character, not two of these: '

Crap, man, I have no idea what kind of keyboard you have, or even where you're getting the open/close variety of double-quote. Presuming you have a normal American/English keyboard, look at the dam' key just to the left of ENTER. It has a double quote and a single quote on it. Press SHIFT to get the double quote. Don't use some kind of editor or word-processor that substitutes in the open/close variety.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Sep 8th, 2007, 7:54 AM   #7
boraciner
Programmer
 
boraciner's Avatar
 
Join Date: Nov 2005
Location: Turkey
Posts: 93
Rep Power: 3 boraciner is on a distinguished road
Ok sir , I understand what you say , I tried again then terminal said ;

I wrote these codes :

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
int
main(int argc,char **argv) {
    int z;                   /* Status return code */
    int s[2];                /* Pair of sockets */
    /*
      * Create a pair of local sockets:
      */
    z = socketpair(AF_LOCAL,SOCK_STREAM,0,s);
    if ( z == -1 ) {
         fprintf(stderr,
            ''%s: socketpair(AF_LOCAL,SOCK_STREAM,0)\n'',
             strerror(errno));
         return 1;           /* Failed */
    }
    /*
      * Report the socket file descriptors returned:
      */
    printf(''s[0] = %d;\n'',s[0]);
    printf(''s[1] = %d;\n'',s[1]);
    system(''netstat --unix -p'');
    return 0;
}


bora@ciner:~/Desktop> gcc bora.c -o bora `pkg-config --cflags --libs gtk+-2.0`
bora.c:18:13: error: empty character constant
bora.c: In function ‘main’:
bora.c:18: error: invalid operands to binary %
bora.c:18: error: expected ‘)’ before ‘:’ token
bora.c:18: error: stray ‘\’ in program
bora.c:18:55: error: empty character constant
bora.c:25:12: error: empty character constant
bora.c:25: error: expected ‘)’ before ‘s’
bora.c:25: error: stray ‘\’ in program
bora.c:25:26: error: empty character constant
bora.c:26:12: error: empty character constant
bora.c:26: error: expected ‘)’ before ‘s’
bora.c:26: error: stray ‘\’ in program
bora.c:26:26: error: empty character constant
bora.c:27:12: error: empty character constant
bora.c:27: error: expected ‘)’ before ‘netstat’
bora.c:27:31: error: empty character constant


I think there are less errors then the other , but I can't compile it again..
boraciner is offline   Reply With Quote
Old Sep 8th, 2007, 7:55 AM   #8
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
See my previous response. You may have additional problems, but you need to get around this one, first.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Sep 8th, 2007, 8:00 AM   #9
boraciner
Programmer
 
boraciner's Avatar
 
Join Date: Nov 2005
Location: Turkey
Posts: 93
Rep Power: 3 boraciner is on a distinguished road
I have put '' (by pressing 2 times) character instead of " which is created by pressing one time. there are errors again but aren't as much as it was
boraciner is offline   Reply With Quote
Old Sep 8th, 2007, 8:12 AM   #10
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Don't use two single quotes! Use one double quote!
I don't know any other way to say that, without getting unduly profane.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
The basic of basic in programming... Simongcc Software Design and Algorithms 4 Aug 16th, 2007 3:34 AM
Slackware installation guide for Linux beginners coldDeath Coder's Corner Lounge 104 Jul 29th, 2007 4:40 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:36 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC