Re: segmentation fault
- From: "Malcolm McLean" <regniztar@xxxxxxxxxxxxxx>
- Date: Sat, 30 Jun 2007 17:46:14 +0100
"sid" <kingsiddharth@xxxxxxxxx> wrote in message news:1183217437.329750.227550@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi!The bug is almost never with the compiler, particuarly when the language is a stable one like C.
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)
{
while((c = getchar()) != EOF)
putchar(tolower(c));
}
else
{
while((c = getchar()) != EOF)
putchar(toupper(c));
}
return 0;
}
In this case you've forgotten that C counts from 0 to N-1 in array indices.
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm
.
- References:
- segmentation fault
- From: sid
- segmentation fault
- Prev by Date: Struct assignment
- Next by Date: Re: Struct assignment
- Previous by thread: Re: segmentation fault
- Next by thread: Re: segmentation fault
- Index(es):
Relevant Pages
|