Results 1 to 2 of 2
Hello, I am still new with programming in C through Fedora terminal.
I am trying to get an early start on my lab that is on Wed. - so I ...
- 12-02-2008 #1Just Joined!
- Join Date
- Sep 2008
- Location
- Buffalo, NY
- Posts
- 25
"Stray" errors while compiling
Hello, I am still new with programming in C through Fedora terminal.
I am trying to get an early start on my lab that is on Wed. - so I copy and paste the code and I get Stray errors. I don't know id the "\" is the cause and before I start removing code from the lab, I want to know what is causing this issue. If I comment the lines out, the program while compile so I know it happens to do with those two lines. I "google" the errors and the results seem to be the inputting characters that aren't ASC. Can someone please explain this issue to happen because this is happening on more than one lab for the future. Thanks!
Code:
Error Code:Code:#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #define MYPORT 4950 // the port users will be connecting to #define MAXBUFLEN 100 int main(void) { int sockfd; struct sockaddr_in my_addr; // my address information struct sockaddr_in their_addr; // connectors address information socklen_t addr_len; int numbytes; char buf[MAXBUFLEN]; if ((sockfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1) { perror("socket"); exit(1); } my_addr.sin_family = AF_INET; // host byte order my_addr.sin_port = htons(MYPORT); // short, network byte order my_addr.sin_addr.s_addr = INADDR_ANY; // automatically fill with my IP memset(&(my_addr.sin_zero), \0, 8); // zero the rest of the struct if (bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) == -1) { perror("bind"); exit(1); } addr_len = sizeof(struct sockaddr); if ((numbytes=recvfrom(sockfd, buf, MAXBUFLEN-1 , 0, (struct sockaddr *)&their_addr, &addr_len)) == -1) { perror("recvfrom"); exit(1); } printf("got packet from %s\n",inet_ntoa(their_addr.sin_addr)); printf("packet is %d bytes long\n",numbytes); buf[numbytes] = \0; printf("packet contains \"%s\"\n",buf); close(sockfd); return 0; }
Code:listener.c: In function main: listener.c:27: error: stray \342 in program listener.c:27: error: stray \200 in program listener.c:27: error: stray \231 in program listener.c:27: error: stray \ in program listener.c:27: error: stray \342 in program listener.c:27: error: stray \200 in program listener.c:27: error: stray \231 in program listener.c:41: error: stray \342 in program listener.c:41: error: stray \200 in program listener.c:41: error: stray \231 in program listener.c:41: error: stray \ in program listener.c:41: error: stray \342 in program listener.c:41: error: stray \200 in program listener.c:41: error: stray \231 in program
- 12-02-2008 #2Just Joined!
- Join Date
- Sep 2008
- Location
- Buffalo, NY
- Posts
- 25
This seems to fix it, am I correct?
Code:from: memset(&(my_addr.sin_zero), \0, 8); to memset(&(my_addr.sin_zero), '\0', 8);


Reply With Quote