LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 01-22-2011, 11:10 AM   #1
Cavatar
LQ Newbie
 
Registered: Jan 2011
Posts: 1

Rep: Reputation: 0
This tiny C program produces a seg fault on slackware64 13.1


this is on slackware64 13.1 running with an amd processor 4gig mem.............

#include <stdio.h>

#define IN 1 /* in a word */
#define OUT 0 /* out of a word */

/* copyright 2011 The Cavater. . . . Master of all C Elements
program prints its input one word per line */

main()
{
char c;
int state;

state = OUT;

while ((c = getchar()) != 'x') {
if (c == ' ' || c == '\t' || c == '\n')
state = OUT;
else if (state == OUT)
state = IN;
if (state == IN)
printf("%s", c);

}
}
 
Old 01-22-2011, 11:20 AM   #2
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,901

Rep: Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025
Quote:
Originally Posted by Cavatar View Post
this is on slackware64 13.1 running with an amd processor 4gig mem.............

#include <stdio.h>

#define IN 1 /* in a word */
#define OUT 0 /* out of a word */

/* copyright 2011 The Cavater. . . . Master of all C Elements
program prints its input one word per line */

main()
{
char c;
int state;

state = OUT;

while ((c = getchar()) != 'x') {
if (c == ' ' || c == '\t' || c == '\n')
state = OUT;
else if (state == OUT)
state = IN;
if (state == IN)
printf("%s", c);

}
}
should be "%c" c is a character, not a string (null terminated array of characters).
 
  


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
strcat is causing seg fault (c program) mfrick Programming 9 08-20-2014 07:34 AM
[SOLVED] Seg Fault when running C program without root MrUmunhum Programming 4 03-30-2009 03:46 PM
seg fault / mem fault - in cron, but works in shell? kauaikat Red Hat 1 04-29-2008 04:24 PM
"C" program creates Seg fault 320mb Programming 4 06-24-2006 02:31 PM

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

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