Mega Code Archive

 
Categories / C / Development
 

Swaps each set of two lines

#include <stdio.h> #include <string.h> int main(void) { char line[1024]; char *ptr = NULL; int i = 0; while(fgets(line, 1024, stdin) != NULL) { i++; if(i == 1) ptr = strdup(line); if(i == 2) { printf("%s", line); printf("%s", ptr); i = 0, free(ptr), ptr = NULL; } } return 0; }