Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Defensive Programming Squad

Name: Anonymous 2008-10-22 5:59

In this thread we pick up innocent programs and tank the shit out of them.

#include <stdio.h>
int main () {
  int n1, n2;
  printf("First integer:");
  scanf("%d", &n1);
  printf("Second integer:");
  scanf("%d", &n2);
  printf("Sum = %d\n", n1+n2);
  return 0;
}

Name: Anonymous 2008-10-23 6:13

>>9
the C99 standard specifies that int main(void) { /* ... */ }, int main(int argc, char *argv[]) { /* ... */ }, or equivalent are valid in 5.1.2.2.1.
in 6.7.5.3 it specifies:
The special case of an unnamed parameter of type void as the only item in the list specifies that the function has no parameters.
and
An empty list in a function declarator that is part of a definition of that function specifies that the function has no parameters.
so int main(void) { /* ... */ } and int main() { /* ... */ } are equivalent.

>>12
#include <stdio.h>
#include <gmp.h>

#define READ_INTEGER(n) (<%\
 mpz_inp_str((n), stdin, 10);\
 fpurge(stdin);\
%>)

int main()<%
 mpz_t n1, n2;
 mpz_init(n1);
 mpz_init(n2);
 setvbuf(stdout, NULL, _IONBF, 0);
 setvbuf(stdin, NULL, _IOLBF, 0);
 printf("First integer:");
 READ_INTEGER(n1);
 printf("Second integer:");
 READ_INTEGER(n2);
 printf("Sum = ");
 mpz_add(n1, n1, n2);
 mpz_out_str(stdout, 10, n1);
 puts("");
 return 0;
%>

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List