Skip to content

Instantly share code, notes, and snippets.

@axgle
Created October 30, 2009 04:52
Show Gist options
  • Save axgle/222133 to your computer and use it in GitHub Desktop.
Save axgle/222133 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main(){
FILE *ff;
char s[255];
ff=fopen(__FILE__,"r");
int num=0;
while(fgets(s,255,ff)){
num++;
printf("%d %s",num,s);
}
fclose(ff);
return 0;
}
========with filename==========
#include <stdio.h>
#include <stdlib.h>
int main(int c, char *argv[]){
if(c!=2){
puts("please input filename");
exit(0);
}
FILE *ff;
char s[255];
ff=fopen(argv[1],"r");
int num=0;
while(fgets(s,255,ff)){
num++;
printf("%d %s",num,s);
}
fclose(ff);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment