• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Shared memory. Program that simulates client - server communication.  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody.

I have client.c and server.c programs. The client should send the characters from a to z and the server convert them in uppercase.

client.c


server.c



When I compile client.c I get this warnings:

client.c: In function ‘main’:
client.c:21:15: warning: passing argument 2 of ‘strcpy’ makes pointer from integer without a cast [-Wint-conversion]
   strcpy(str,c);
              ^
In file included from client.c:4:0:
/usr/include/string.h:121:14: note: expected ‘const char * restrict’ but argument is of type ‘char’
extern char *strcpy (char *__restrict __dest, const char *__restrict __src)




When I run it I get this message:

Segmentation fault (core dumped)



Any way to fix this?

 
Bartender
Posts: 20742
124
Android Eclipse IDE Java Linux Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Don't use strcpy like that. What you are actually telling the compiler is that you want to copy strings from memory locations 65, then 66, then 67, ...

Because strcpy works with pointers, not with character values. So the manifest constant 'a' gets translated into an integer equivalent to its ASCII code value (65), and strcpy attempts to copy characters starting at memory location 65. Which is generally hardware-protected low memory.

That's not a problem with shared memory or with client/server. You have failed at a basic C function. And C isn't very forgiving of failure.
 
What's wrong? Where are you going? Stop! Read this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!