LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Fedora
User Name
Password
Fedora This forum is for the discussion of the Fedora Project.

Notices


Reply
  Search this Thread
Old 10-07-2005, 01:56 AM   #1
dludenar
Member
 
Registered: Sep 2005
Location: Japan
Distribution: CentOS 5.2 / Fedora Core 8
Posts: 41

Rep: Reputation: 20
Error in program


Hello people

I'm beggining programming in C, well now I have problems with the following program:

#include <stdio.h>

main()

{
int c, i, letter[26];
FILE *fp, *fopen();

fp = fopen("chapter1", "r");
for (i = 0; i < 26; ++i) /* initialize array to cero */
letter[i] = 0;
while ((c = getc(fp)) != EOF)
if ('A' <= c && c <= 'Z')
++letter [c - 'A'];
for (i = 0; i < 26; ++i)
{
if (i % 6 == 0)
printf ("\n");
printf ("%5c:%5d", 'A' + 1, letter[i]);
}
printf ("\n\n");
}

When I compilled it no erros, no warnings, but when I excecuted, says: "Segmentation fault"

Can anyone help me to solve this problem??? I hope so.

Regards

dludenar
 
Old 10-07-2005, 03:20 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
this should have really breen posted in the programming forum, but never mind.

When you have segmentation faults, you should get used to using the GNU debugger to step through the fault and get more information yourself. just run "gdb ./myprogram" and execute a "run" when it loads. once it crashes use "bt" to print a backtrace of what was happening at the time.
 
  


Reply



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
error while compiling c /c++ program kiranbud Programming 1 10-12-2005 08:19 PM
error compiling a program minm Linux - Newbie 7 08-01-2005 10:40 AM
Program error mdkusr Linux - General 2 03-12-2005 01:19 PM
Error for a very simple C program pkashyap Linux - Newbie 2 03-11-2004 10:24 AM
C Program Error? linux_GNUbie Programming 5 12-01-2003 03:18 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Fedora

All times are GMT -5. The time now is 11:44 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration