Re: segmentation fault
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Sat, 30 Jun 2007 15:04:44 -0400
sid wrote:
I am using gcc (GCC) 4.0.3 (Ubuntu 4.0.3-1ubuntu5) on an Ubuntu
6.06 64bit version on an AMD 64bit machine. Each time I compile
and execute the following program I get segmentation fault. Please
tell me whether the code I have written has some errors or whether
there is problem with my OS or the compiler.
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(int argc,char *argv[])
{
int c;
if(argc == 0)
printf("\nNo Arguments\n");
else if(strcmp(argv[argc],"lower") == 0)
This should use "argc-1". argv[argc] is always NULL. Your system
apparently faults on passing NULL to strcmp (which is allowable).
{
while((c = getchar()) != EOF)
putchar(tolower(c));
}
else
{
while((c = getchar()) != EOF)
putchar(toupper(c));
}
return 0;
}
Most systems will never have "argc == 0" since argc[0] is used to
transmit the name of the running program. Not always so, though.
Tip: Don't use tabs, use spaces, especially in Usenet postings.
--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net
--
Posted via a free Usenet account from http://www.teranews.com
.
- References:
- segmentation fault
- From: sid
- segmentation fault
- Prev by Date: Re: Machine epsilon: conclusion
- Next by Date: Re: Machine epsilon: conclusion
- Previous by thread: Re: segmentation fault
- Next by thread: Struct assignment
- Index(es):
Relevant Pages
|