![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Nov 2005
Location: Turkey
Posts: 93
Rep Power: 3
![]() |
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` |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Nov 2005
Location: Turkey
Posts: 93
Rep Power: 3
![]() |
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. |
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#5 |
|
Programmer
Join Date: Nov 2005
Location: Turkey
Posts: 93
Rep Power: 3
![]() |
ok! I will try '' in a moment. I'll write what terminal displays.
|
|
|
|
|
|
#6 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#7 |
|
Programmer
Join Date: Nov 2005
Location: Turkey
Posts: 93
Rep Power: 3
![]() |
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.. ![]() |
|
|
|
|
|
#8 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#9 |
|
Programmer
Join Date: Nov 2005
Location: Turkey
Posts: 93
Rep Power: 3
![]() |
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 |
|
|
|
|
|
#10 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |