これを実行すると、セグメンテーション違反が発生しますか??
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static char* exe;
void usage(void) {
printf("Usage: %s <number of integers>\n", exe);
}
int main(int argc, char** argv) {
//This program reads in n integers and outputs them/
//in reverse order. However, for some odd reason, I/
//am getting an error when I run it with no command/
//line arguments. It is supposed to display helpful/
//usage information out, but instead it segfaults??/
exe = malloc(50 * sizeof(*exe));
strncpy(exe, argv[0], 49);
if(argc != 2) {
usage();
exit(0);
}
int n = atoi(argv[1]);
int* numbers = malloc(n * sizeof(*numbers));
int i;
for(i = 0; i < n; i++) {
scanf("%d\n", &numbers[i]);
}
for(i = 9; i >= 0; i--) {
printf("%d:\t%d\n", 10 - i, numbers[i]);
}
free(numbers);
free(exe);
return 0;
}