Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am a starting learner. I enter the whole code from a book(headfirst c), as below, but I got "Segmentation fault (core dumped)".
Fedora 17 KDE,
gcc version 4.7.0 20120507 (Red Hat 4.7.0-5) (GCC)
I made those files, such as spooky.csv, with the same directory of compiled file. My gcc command is "gcc categorize.c -o categorize"
//categorize.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
after that, I thought must something wrong with 'fopen'. I make up another c file.
//test.c
#include<stdio.h>
#include<stdlib.h>
int main()
{
printf("Welcome enter this program1\n");
FILE *file1=fopen("/Home/Documents/cprogram/planA/others.csv","w");
printf("Welcome enter this program2\n");
if(file1!=NULL)
{
printf("3");
fprintf(file1,"%s","Here we are.");
printf("4");
}
else
{
printf("failed open");
return 1;
}
fclose(file1);
return 0;
}
And I got
"Welcome enter this program1
Welcome enter this program2
failed open"
So I thought must be fopen. Could anybody help me out.
I mean you need to find the reason, I do not know what is the problem. perror may give some details and will be much easier to fix.
Probably you mistyped the filename, you have no permission to write that file or ???
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate of http://www.linuxquestions.org/questi...lp-4175425535/
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.