News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Use of files containing source code

Started by richard7298, October 25, 2018, 09:17:20 PM

Previous topic - Next topic

richard7298

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

BlueHazzard

QuoteBut, 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...

QuoteWhen 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

richard7298

#2
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

stahta01

C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

BlueHazzard

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...

richard7298

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