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


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

Rep: Reputation: 20
Problems with program


Hello people

I'm starting programming in C, I am studying from this book "A book on C" of Al Kelley & Ira Pohl, but I have one problems with the following program:

#include <stdio.h>
#define MAXWORD 100

main ()

{
char *find_next(), word[MAXWORD];
int char_cnt = 0, word_cnt = 0, word_lenght = 0;

while (find_next(word) != NULL)
{
capitalize(word);
++word_cnt;
word_lenght = strlen(word);
char_cnt += word_lenght;
printf ("\n%12d %s", word_lenght, word);
}
printf ("\n\n%12d characters in %d words\n\n",
char_cnt, word_cnt);
}

char *find_next(word)
char word[];
{
int c, i;

while ((c = getchar()) == ' ' || c == '\n' || '\t')
; /* skip white space */
if (c != EOF)
{
i = 0;
while (c != ' ' && c != '\n' && c != '\t' && c != EOF)
{
word[i++] = c;
c = getchar ();
}
word[i] = '\0';
return (word);
}
else
return (NULL);
}

capitalize(p)
char *p;
{
for ( ; *p != '\0'; ++p)
if ('a' <= *p && *p <= 'z')
*p += 'A' - 'a';
}

When you input the following text "she sells sea shells by the seashore", at the moment of excecute the program, the result must be:

3 SHE
5 SELLS
3 SEA
6 SHELLS
2 BY
3 THE
8 SEASHORE

When I compilled there's no problem, no errors no warnings, but when I excecute and introduce the text it doesn't work, I hope you could help me, I am using Fedora Core 3.

Thanks
 
Old 10-07-2005, 01:55 AM   #2
dludenar
Member
 
Registered: Sep 2005
Location: Japan
Distribution: CentOS 5.2 / Fedora Core 8
Posts: 41

Original Poster
Rep: Reputation: 20
Error when excecute 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:18 AM   #3
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
Please do not post the same thread in more than one forum. Picking the most relevant forum and posting it once there makes it easier for other members to help you and keeps the discussion all in one place.

http://www.linuxquestions.org/rules.php
 
Old 10-07-2005, 06:06 AM   #4
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
Closed.
 
  


Closed Thread



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
problems with program using wine degraffenried13 Linux - Software 4 12-05-2004 09:33 AM
Problems compiling C program Boba Programming 3 08-28-2004 06:31 PM
more program problems pguru Linux - Newbie 2 06-26-2004 09:28 AM
Program Installation Problems pirinoe Linux - Newbie 5 10-15-2003 03:04 AM
program problems vegasect Linux - Newbie 1 08-02-2003 08:28 PM

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

All times are GMT -5. The time now is 04:30 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