![]() |
| | #1 |
| Registered User Join Date: Dec 2001
Posts: 25
| cygwin -> unix , my code not working properly ;( I recently make this code to concate 2 string...i am using cygwin at home...and this code working as i expected : Code: char *str_concat( char *string1, char *string2 )
{
char *string3;
char *concated_string;
int len1, len2;
/* edited */
string3 = '\0';
return concated_string;
}
however when try to run it at school, in unix machine it doesn't work ( I've change the file format using dos2unix ). if i put str_concat( mike, mike ) it will return "mikemikelv55/k" (without quote) instead of "mikemike" -> and somethin weird, it not always giving addition "lv55/k" sometimes it gives like "xxlv55/k/x" in the back...always in the back... this is mess up the whole program of mine ;( it is due on monday..and only becoz of one small part not working, the whole program not gonna work ) pls help Ferdinand Last edited by CyC|OpS; 05-18-2002 at 07:25 AM. |
| CyC|OpS is offline | |
| | #2 |
| and the hat of vanishing Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,214
| > string3 = '\0'; Should be *string3 = '\0'; Oh, and you don't (or perhaps shouldn't) cast the result of malloc. |
| Salem is offline | |
| | #3 |
| Registered User Join Date: Dec 2001
Posts: 25
| Thanks Salem!!! It did workingggg, omg i dont believe it... thank you very much ![]() o yeah about the malloc... do u mean that I dont need to allocated the memory? sincerely, ferdinand |
| CyC|OpS is offline | |
| | #4 |
| and the hat of vanishing Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,214
| > do u mean that I dont need to allocated the memory Yes you DO need to allocate the memory But it's better to write this in ANSI-C string3 = malloc( len1 + len2 + 1 ); If you've included stdlib.h, then the normal C rules for converting void* into the appropriate type will take over for you If you haven't included stdlib.h, you will get a warning (a warning which the cast will suppress) |
| Salem is offline | |
| | #5 |
| Registered User Join Date: Dec 2001
Posts: 25
| oh okie... i dont know about that =) I think thread closed now. Last edited by CyC|OpS; 05-18-2002 at 05:35 AM. |
| CyC|OpS is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to properly call an executable from C code? | remy06 | C Programming | 3 | 05-14-2009 03:48 AM |
| Who will map the scan code (inserted by VKD_Force_keys) to virtual key code? | Unregistered | Windows Programming | 0 | 02-21-2002 06:05 PM |
| opengl code not working | Unregistered | Windows Programming | 4 | 02-14-2002 10:01 PM |
| Working Code Samples Wanted | Unregistered | C Programming | 2 | 02-13-2002 10:05 PM |
| Linked List Working Code | Linette | C++ Programming | 9 | 01-24-2002 12:00 PM |