File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes string help stuff... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "string help stuff..." Watch "string help stuff..." New topic

string help stuff...

Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
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,


You down with OOP? Yeah you know me!
Srinivas Kalvala
Ranch Hand

Joined: Oct 20, 2005
Posts: 257


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


Unix Network programming by Stevens
Henry Wong

Joined: Sep 28, 2004
Posts: 20517

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...

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15081

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 ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490 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.

"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
I agree. Here's the link:
subject: string help stuff...
It's not a secret anymore!