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