Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

string help stuff...

 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok i know this isnt a java question, but this is the best online forum
for programmers so here it goes...

umm, i'm using C in my computer networks class...

and in one program they initiate a character array of a defined BUFFSIZE.

like so:

char buff[BUFFSIZE];

and they use readln to get user input and store it into that array.

like so:



now, i want to send an error message if, when i try to read a file,
it returns null..

i know how to create a char[] but how do i store the string

say: " file did not exist, was created" into the char[] in C

please help me,


Justin
 
Srinivas Kalvala
Ranch Hand
Posts: 257
Firefox Browser Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

memcopy() and memset() will help. Try them

Refer:

Unix Network programming by Stevens
 
Henry Wong
author
Marshal
Pie
Posts: 21506
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As already mentioned, in order to copy strings around, you can use the memcopy() function. To create a string with a value, I believe it is...



Of course, my "C" is incredibly rusty...
Henry
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15490
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that in C it should be memcpy without the o, not memcopy. For strings you should use strcpy instead of memcpy.

[ September 14, 2006: Message edited by: Jesper Young ]
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://www.programmersheaven.com/c/MsgBoard/grouplist.asp?Setting=A0001F2001 has a bunch of great C boards, along with lots of other subjects. I think it is the best all around programming board. The Java boards are pretty dead, but the boards labeled C/C++ are quite active and the regulars are not only nice, but extremely knowledgable in CS topics.

It sounds like you are in need of a good beginners book. Didn't this class have C as a prereq? A Book on C is an outstanding book that covers ANSI C. And as noted, Unix Network Programming is the definitive networking book, although it actually expects the reader to be comfortable in the basics of C, which is more then fair.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic