![]() |
| | #1 |
| Registered User Join Date: Mar 2008
Posts: 39
| Code: int main()
{
char* date1="Dec 29, 8:30";
char* date2="Dec 28, 7:30";
char* year =" 2009";
strcat(date1,year);
strcat(date2,year);
return 0;
}
Code: red 312 % time.out Segmentation fault Thanks |
| thungmail is offline | |
| | #2 |
| Registered User Join Date: Feb 2009
Posts: 35
| strcat adds on the second string to the end first string. so you have to leave some space at the end of the first string. for example Code: char date1[20]="Dec 29, 8:30";
char date2[20]="Dec 28, 7:30";
char* year =" 2009";
strcat(date1,year);
strcat(date2,year);
printf("%s\n%s\n", date1, date2);
|
| Brain_Child is offline | |
| | #3 |
| Jack of many languages Join Date: Nov 2007 Location: Katy, Texas
Posts: 1,929
| Also, when declaring strings like that, your compiler may mark those strings to be placed into read-only memory when the program is loaded, and thus adding more room to them to do a strcat() later might be a fruitless effort.
__________________ Mac and Windows cross platform programmer. Ruby lover. Memorable Quotes From Recent Posts: I can't remember. |
| Dino is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| An interesting question about strcat | meili100 | C++ Programming | 3 | 07-07-2009 12:59 PM |
| Question about pointers #2 | maxhavoc | C++ Programming | 28 | 06-21-2004 12:52 PM |
| Question... | TechWins | A Brief History of Cprogramming.com | 16 | 07-28-2003 09:47 PM |
| opengl DC question | SAMSAM | Game Programming | 6 | 02-26-2003 09:22 PM |
| Question, question! | oskilian | A Brief History of Cprogramming.com | 5 | 12-24-2001 01:47 AM |