Skip to content

Instantly share code, notes, and snippets.

@HarDToBelieve
Last active April 11, 2016 12:21
Show Gist options
  • Save HarDToBelieve/d1f66ca1bb2c2a3c93b0efd563f95098 to your computer and use it in GitHub Desktop.
Save HarDToBelieve/d1f66ca1bb2c2a3c93b0efd563f95098 to your computer and use it in GitHub Desktop.
// Linux 32bit: gcc -pwn2.c
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#define maxlen 20
struct {
int admin;
int buffer[maxlen];
} array;
void print_arr(int buf[]) {
int i;
printf ("buffer: ");
for (i=0; i<maxlen; ++i)
printf ("%d ", buf[i]);
printf ("\n");
}
int main () {
srand(time(0));
int i;
array.admin = 0;
for (i=0; i<maxlen; ++i)
array.buffer[i] = rand() % 10;
print_arr(array.buffer);
puts("Input the element you want to change value: ");
int ind;
scanf("%d", &ind);
if ( ind < maxlen ) {
puts("New value: ");
int val;
scanf("%d", &val);
array.buffer[ind] = val;
}
else {
puts("Failed!");
}
if ( array.admin == 1 ) {
puts("You win!");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment