Innight Posted May 31, 2009 at 04:05 PM Report #268760 Posted May 31, 2009 at 04:05 PM Boa tarde. #include <stdio.h> #include <io.h> #include <stdlib.h> int main(void) { FILE *fp; char s[80]; int t; if((fp=fopen("test", "w")) == NULL) { printf("Cannot open file.\n"); exit(1); } printf("Enter a string and a number: "); fscanf(stdin, "%s%d", s, &t); /* read from keyboard */ fprintf(fp, "%s %d", s, t); /* write to file */ fclose(fp); if((fp=fopen("test","r")) == NULL) { printf("Cannot open file.\n"); exit(1); } fscanf(fp, "%s%d", s, &t); /* read from file */ fprintf(stdout, "%s %d", s, t); /* print on screen */ return 0; } Tenho este codigo mas cada vez eu abro o pograma ele substitui o que tem por eu meter de novo por exemplo queria: introduzir a primeira vez ola 123 introduzir segunda vez adeus 456 ou seja ficar ola 123 adeus 456 alguma ideia?
nata79 Posted May 31, 2009 at 04:08 PM Report #268761 Posted May 31, 2009 at 04:08 PM no fopen em vez de meteres "w" mete "a" http://en.wikipedia.org/wiki/Fopen#Opening_a_file_using_fopen arithmeticoverflow.wordpress.com
Innight Posted May 31, 2009 at 04:20 PM Author Report #268763 Posted May 31, 2009 at 04:20 PM Obrigado ja resolveu.e agora se eu quiser ler todo o notepad no inicio como eu fazo?
Innight Posted May 31, 2009 at 04:55 PM Author Report #268766 Posted May 31, 2009 at 04:55 PM ja resolvi obrigado fp = fopen ( "test", "r" ); if ( fp != NULL ) { char line [ 10 ]; while ( fgets ( line, sizeof line, fp ) != NULL ) fputs ( line, stdout ); }
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now