Author Topic: Use of files containing source code  (Read 2666 times)

Offline richard7298

  • Single posting newcomer
  • *
  • Posts: 3
Use of files containing source code
« on: October 25, 2018, 09:17:20 pm »
Hi. I'm a complete newbie to CB and writing code. I'm mostly interested in running code for console applications.

I've copied and pasted into Notepad some simple code I found on the internet.  I've added this file to a Project. When I run debug there is a failure.  But, first of all, should the file containing source code, that I have added to the Project, come under "Others" or should it be saying "Sources"? Thanks. Rich

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Use of files containing source code
« Reply #1 on: October 25, 2018, 09:44:52 pm »
Quote
But, first of all, should the file containing source code, that I have added to the Project, come under "Others" or should it be saying "Sources"?
What? If you create a project it will create a .c or .cpp file. This files are automatically added to the virtual source folder in codeblocks. Your source files always have to end with .c or .cpp (or other common c++ file endings like .cxx). If the do not end with the right ending codeblocks does not know how to compile them...

Quote
When I run debug there is a failure
Without exact error message no help.... http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_(general)#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F

Offline richard7298

  • Single posting newcomer
  • *
  • Posts: 3
Re: Use of files containing source code
« Reply #2 on: October 25, 2018, 10:03:17 pm »
HI. OK, it's as I thought. My .txt file is under "Other" because it's not a source file.

Anyway, I've just got to figure out how I can take code from websites and get it into CB.  I just now created a new (blank) source file in CB.

EDIT: I added the .txt file to the Project. Then I copied and pasted the code from the .txt file into the new source file.  Then I un-added the .txt file. And the code runs OK. Whether this is how one should go about getting code into CB, I know not. But it did work. Rich
« Last Edit: October 25, 2018, 10:15:49 pm by richard7298 »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7588
    • My Best Post
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Use of files containing source code
« Reply #4 on: October 26, 2018, 03:10:36 am »
Quote
EDIT: I added the .txt file to the Project. Then I copied and pasted the code from the .txt file into the new source file.  Then I un-added the .txt file. And the code runs OK. Whether this is how one should go about getting code into CB, I know not. But it did work. Rich
Why not renaming the .txt file to a .c file?
source files are text files with a other ending...

Offline richard7298

  • Single posting newcomer
  • *
  • Posts: 3
Re: Use of files containing source code
« Reply #5 on: October 26, 2018, 10:22:35 am »
Changing the extension from .txt to .c worked perfectly. Changing the file extension was the first thing I thought about, but because only the name of the file was highlighted when I clicked on "Rename" I thought I could not change the extension. Anyway, I'm now sorted. Thanks. Rich