LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-23-2005, 08:44 PM   #1
nelnel
Member
 
Registered: May 2005
Posts: 47

Rep: Reputation: 15
Segmentation fault cause by String type


hi,
i am making a simple program to convert the string type, but when i run a simple program for string testing , it cause the Segmentation fault...
i don't know iit is because of the String or pointer problem..

source code :

#include <stdio.h>
#include <iostream.h>
#include <string>

using std::string;
using std::endl;
using std::cout;

int main()
{
cout << "IO TEST" << endl;
FILE *fp;
char *m_Directory = "/root/qtest/file_io_test";
char *m_CPM_File = "a.cpm";
char *str_filename;
int temp_num = 2;
string temp_str("");
strcpy(str_filename,m_Directory);
strcat(str_filename,"/");
strcat(str_filename,m_CPM_File);

fp = fopen("str_filename","wt");
cout << str_filename << endl;

temp_str+="BEGIN,";
temp_str+="\n";
// temp_str = "BEGIN," + temp_num + "\n";
cout << temp_str <<endl;
return 0;
}


thx for ur help!!!
 
Old 08-23-2005, 09:32 PM   #2
lordofring
Member
 
Registered: Feb 2005
Posts: 91

Rep: Reputation: 15
str_filename isn't allocated memory. strcpy rises the problem
 
Old 08-23-2005, 09:46 PM   #3
nelnel
Member
 
Registered: May 2005
Posts: 47

Original Poster
Rep: Reputation: 15
OH, i get it ,thx
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika Suse/Novell 2 12-02-2005 09:34 AM
segmentation fault libriana Linux - Newbie 2 06-10-2005 05:52 PM
Help! Segmentation Fault qieqie Linux - Newbie 3 06-03-2005 09:10 PM
segmentation fault in c++ drigz Programming 10 06-16-2004 03:06 PM
segmentation fault ! wwnn1 Programming 7 06-18-2002 09:48 AM


All times are GMT -5. The time now is 05:13 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration