• 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 ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
  • Tim Holloway
  • Carey Brown
  • salvin francis

Shared memory. Program that simulates client - server communication.

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.



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]
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?

Posts: 21000
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • 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.
A feeble attempt to tell you about our stuff that makes us money
professionally read, modify and write PDF files from Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!