Re: segmentation fault
- From: Harald van Dijk <truedfx@xxxxxxxxx>
- Date: Sat, 30 Jun 2007 17:46:59 +0200
sid wrote:
Hi!
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.
You're passing argv[argc] to strcmp, but argv[argc] is always NULL. Did you
perhaps mean argv[1]? (If you did, you will also need to change your
argc == 0 check, in case argc is exactly 1.)
#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;
}
- References:
- segmentation fault
- From: sid
- segmentation fault
- Prev by Date: Re: segmentation fault
- Next by Date: Re: file shredding
- Previous by thread: Re: segmentation fault
- Next by thread: Re: segmentation fault
- Index(es):
Relevant Pages
|