User forums > General (but related to Code::Blocks)

How to debug when the inputs getted from a text file?

<< < (2/2)

BlueHazzard:
It could be possible if you are on linux. On windows it is probably not that easy...
One possibility would be that you run your application from outside codeblocks and attach the debugger to it with Debug->Attach to process

You can try to go this way: https://stackoverflow.com/a/4758218
the

--- Code: ---cat < test.txt
--- End code ---
part is set in Project->Set program arguments

If i were you I would embedd the file reading in your code...

--- Code: ---nt main()
{
   FILE *fp;
 
   fp = fopen("test.txt", "r"); // read mode
 
   if (fp == NULL)
   {
      perror("Error while opening the file.\n");
      exit(EXIT_FAILURE);
   }

    while((ch=fgetc(fp))!=EOF)
    {
        putchar(ch);
    }
   fclose(fp);
   return 0;
}

--- End code ---

wanggaoteng:

--- Quote from: BlueHazzard on May 29, 2019, 09:36:30 am ---It could be possible if you are on linux. On windows it is probably not that easy...
One possibility would be that you run your application from outside codeblocks and attach the debugger to it with Debug->Attach to process

You can try to go this way: https://stackoverflow.com/a/4758218
the

--- Code: ---cat < test.txt
--- End code ---
part is set in Project->Set program arguments

If i were you I would embedd the file reading in your code...

--- Code: ---nt main()
{
   FILE *fp;
 
   fp = fopen("test.txt", "r"); // read mode
 
   if (fp == NULL)
   {
      perror("Error while opening the file.\n");
      exit(EXIT_FAILURE);
   }

    while((ch=fgetc(fp))!=EOF)
    {
        putchar(ch);
    }
   fclose(fp);
   return 0;
}

--- End code ---

--- End quote ---

Hi, BlueHazzard,
It's my fault for not telling you that my computer is on ubuntu.
Following your instruction, I create a "text" file in the folder of .cbp, and typing "./test <text" in Project->Set program arguments, then I click the debug button, it solves my problem profectly.
Thank you.
Best Regards.

Navigation

[0] Message Index

[*] Previous page

Go to full version