fork download
  1. #include <stdio.h>
  2.  
  3. int main(void)
  4. {
  5. FILE *fp1, *fp2;
  6. char fname1[256], fname2[256], fname3[256], str[256];
  7. int ch, line, col, linecnt=1, colcnt=1, out=0;
  8.  
  9. printf("filename:"); scanf("%s", fname1);
  10. if ((fp1 = fopen(fname1, "rt")) == NULL) {
  11. printf("Can't open input file(%s)\n", fname1);
  12. return 1;
  13. }
  14. strcpy(fname2, fname1);
  15. strcat(fname2, ".out");
  16. if ((fp2 = fopen(fname2, "w")) == NULL) {
  17. printf("Can't open output file(%s)\n", fname2);
  18. fclose(fp1);
  19. return 1;
  20. }
  21.  
  22. strcpy(fname3, fname1);
  23. strcat(fname3, ".bak");
  24. remove(fname3);
  25.  
  26. printf("insert string:"); scanf("%s", str);
  27. printf("insert line:"); scanf("%d", &line);
  28. printf("insert col:"); scanf("%d", &col);
  29.  
  30. while ((ch = fgetc(fp1)) != EOF) {
  31. if (out == 0 && line == linecnt && col == colcnt){
  32. fprintf(fp2,"%s",str);
  33. out = 1;
  34. }
  35. fputc(ch,fp2);
  36. if (ch == '\n') {
  37. linecnt++;
  38. colcnt = 1;
  39. }else{
  40. colcnt++;
  41. }
  42. }
  43.  
  44. fclose(fp1);
  45. fclose(fp2);
  46.  
  47. rename(fname1, fname3);
  48. rename(fname2, fname1);
  49.  
  50. return 0;
  51. }
  52.  
Runtime error #stdin #stdout 0s 2428KB
stdin
Standard input is empty
stdout
filename:Can't open input file(�t��)