mirror of
https://github.com/adulau/aha.git
synced 2024-12-28 03:36:19 +00:00
Forgot that the index 0 was reserved
This commit is contained in:
parent
16989baa5f
commit
e50b1b2c29
1 changed files with 16 additions and 9 deletions
19
aha/insult.c
19
aha/insult.c
|
@ -7,20 +7,27 @@
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#define N 4
|
#define N 5
|
||||||
char* list[] = {"Fuck you",
|
|
||||||
|
/* The element 0 is reserved for that insult is not set and if the program is
|
||||||
|
* started from the shell with no arguments nothing should happen
|
||||||
|
* atoi(sss) -> 0
|
||||||
|
*/
|
||||||
|
char* list[] = {"",
|
||||||
|
"Fuck you",
|
||||||
"Is that all? I want to do more ...",
|
"Is that all? I want to do more ...",
|
||||||
"Go away",
|
"Go away",
|
||||||
"I love you"};
|
"I love you"};
|
||||||
|
|
||||||
int main(int argc, char* argv[]){
|
int main(int argc, char* argv[]){
|
||||||
int idx;
|
int idx;
|
||||||
if (argc==2){
|
/* If another argv is used, then maybe only argv[0] is allocated when
|
||||||
idx=atoi(argv[1]);
|
* no command lines are delivered. Therefore the kernel overwrites this
|
||||||
|
* to avoid to allocate / smash the stack
|
||||||
|
*/
|
||||||
|
idx=atoi(argv[0]);
|
||||||
if ((idx>=0) && (idx<N))
|
if ((idx>=0) && (idx<N))
|
||||||
printf("%s\n",list[idx]);
|
printf("%s\n",list[idx]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue