• R/O
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

練習用です。いろんなものがごちゃまぜです。


Commit MetaInfo

Revision28 (tree)
Time2015-08-25 18:07:26
Authorbellyoshi

Log Message

Change Summary

Incremental Difference

--- vs2015/edline/edline/edline.c (revision 27)
+++ vs2015/edline/edline/edline.c (revision 28)
@@ -322,7 +322,7 @@
322322 int i;
323323 if (LineCount > 0) {
324324 for (i = start; i <= end;i++) {
325- PrintLine( i, Lines[i - 1]);
325+ PrintLine(i, Lines[i - 1]);
326326 }
327327 }
328328 else {
@@ -340,7 +340,8 @@
340340 fp = fopen(fileName, "r");
341341 if (fp == NULL) {
342342 result = ERROR_CANNOT_OPEN_FILE;
343- } else {
343+ }
344+ else {
344345 while (NULL != fgets(buffer, MAX_CHAR, fp)) {
345346 LineCount++;
346347 }
@@ -350,7 +351,7 @@
350351 pLine = Lines;
351352
352353 c = '\0';
353- while (c != EOF) {
354+ while (c != EOF) {
354355 c = getc(fp);
355356 if ((c == '\n') || ((c == EOF) && (i != 0))) {
356357 buffer[i] = '\n';
@@ -372,8 +373,37 @@
372373 return result;
373374 }
374375 int Quit() {
375- return 0;
376+ char command;
377+ int result = SUCCESS;
378+
379+ printf("保存しますか?(Y/N):");
380+ command = tolower(getchar());
381+ if (command == 'Y'){
382+ result = SaveFile(FileName);
383+ }
384+ return result;
376385 }
377386 int SaveFile(char *fileName) {
378- return 0;
387+ FILE *fp;
388+ int i;
389+ int result = SUCCESS;
390+
391+ if (LineCount > 0) {
392+ fp = fopen(fileName, "w");
393+ if (fp == NULL) {
394+ result = ERROR_CANNOT_OPEN_FILE;
395+ }
396+ else {
397+ for (i = 0; i < LineCount; i++) {
398+ fputs(Lines[i], fp);
399+ }
400+ if (0 != fclose(fp)) {
401+ result = ERROR_CANNOT_CLOSE_FILE;
402+ }
403+ }
404+ }
405+ else {
406+ remove(fileName);
407+ }
408+ return result;
379409 }
\ No newline at end of file