123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|722|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> C/C++/C#/Other -> C and txt files

Tue, 17 Jul 2007, 07:53
iusinbello
In debug.txt I have this string
a.txt$klop

where a.txt is the name of a file and klop a password.
I use this code to get password and the name of the file. I use $ to separate them.




When I try to print out "key" and "namein" strings I get
a.txt¥
klop0$

why?

-=-=-


Tue, 17 Jul 2007, 07:58
garand
It might just be me but that code looks a little complicated for what you are trying to do. I dont know much C at all but in C# I would get a substring from the beginning to the "$" and from the $ to the end. Strip the "$" from it and store each in different variables. Then you would have the txt file and password nomatter how long each of them is. good luck and if i get some time ill try to figure out something for C
Tue, 17 Jul 2007, 08:54
Jayenkai


Stupid C Char returns!
Took a few goes to get that working right, but that function should come in handy for you!

-=-=-
''Load, Next List!''
Tue, 17 Jul 2007, 08:59
iusinbello
Thanks Jay but this is not what I am asking for.
I need to understand why when I try to get a string from a .txt i get weird symbols in it...

P.s. ty garand.

-=-=-


Tue, 17 Jul 2007, 09:27
Jayenkai
Oh, well in that case it's probably the old "Assuming it's blank" issue.

Never assume that a variable is nothing when using C.


So, whenever you add a letter to the end of a char, you should always add a [0] to the point right after it.
In your case : namein[i] = bit; namein[i+1]=0;

-=-=-
''Load, Next List!''
Tue, 17 Jul 2007, 09:58
iusinbello
w00t!! ty now it works fine!
My last question>> why when you declare an array you use
char* name[number]
instead of
char name[number] ???

P.s. i hope those little banners on my sign arent annoying...

-=-=-


Tue, 17 Jul 2007, 10:11
Jayenkai
I started using char* a while back.
To be honest, I'm still not 100% sure what works better.
I think "Char* name" is "Amount of space for text that's this length" and "Char name[number]" is "Amount of space 'number' length" but I might be wrong. I tend to avoid all types of string in C

-=-=-
''Load, Next List!''
Wed, 18 Jul 2007, 16:39
Yayyak

allocates space for a pointer to a set of chars. It does not allocate space for the string.

does basically the same thing.

allocates the pointer, but also the memory for the string itself (of length number).

AFAIK, of course. I don't have my set of bibles with me (in philosophy class...).

Wed, 18 Jul 2007, 18:17
Jayenkai
^ 3 perfectly good reasons to avoid using C!
Wed, 18 Jul 2007, 19:42
Yayyak
That may be true in some cases. I don't develop web applications in C.

C is, however, the lingua franca of computer science. It's also used a lot in library and system development. Even if you don't use it, you still have to put up with it and get used to it.

Plus, it's not that hard, really. Especially compared to the language behemoth that C++ is.