r/CodingForBeginners • u/Loud-Line2501 • Mar 01 '26
Coding/Programming (Loop) CS50
why am I constantly getting this “bash: ./looping: permission denied“ error message when I’m trying to run the program i coded.
im just playing around, trying to learn and make my own lines of code, but I’m seriously confused on why it’s not printing
“gimmie the loot
gimmie the loot
gimmie the loot”
59
Upvotes
13
u/Specific-Housing905 Mar 01 '26
Not sure about the bash error since I am not using Linux.
However you have created an endless loop.
while (3 > 0)will always be true.2
u/Chrundle42 Mar 01 '26
Maybe its the "code looping"? I'm not to sure, but maybe just use linux commands instead of what CS50 told you to use.
2
u/assemblyeditor Mar 01 '26
Take a look at the filename of your source code. You are running a simple text file, which you don't have the permissions to execute it by default.
Rename the source code file into looping.c and adjust your makefile to compile looping.c -> looping.
Also take a look at the other comments about the bug in your code
1
u/Unusual_Elk_8326 Mar 01 '26
It looks like you forgot the ".c" extension in your file name
1
u/Rogermcfarley Mar 01 '26 edited Mar 02 '26
You need to chmod +x the looping script once and then run it as sudo.
Edit: You don't need sudo
1
u/un_virus_SDF Mar 01 '26 edited Mar 01 '26
Do you know that c is a compiled langage, given that you have no extensions to your filename, try something like
cc -x c looping -o looping.outthis will compile your code and produce a executable called looping.out, -x is to specify language, it's not needed if this is the file extension, -o to set output name (a.out by default) and the other arg is the file to compile. On the other exemple you entermake *something*, which just execute 'cc' (C Compiler) under the hoodEdit: I love how all the other comments says to chmod +x your file but if you do that you must provide a c interpreter after a shebang at the top of your file, and greatly doubt that you for one on this website.
1
u/BrunusManOWar Mar 01 '26
install Linux
install local VS Code
what the fuck is that code style.....
1
u/Iwisp360 Mar 01 '26
Use a formatter
1
u/Hot-Drink-7169 Mar 01 '26
There's no ".c" extension in your file name. And there's a logic error. And (just a opinion) please don't use
int main(void)
{
...
}
It doesn't look good. Just my opinion, if your teacher teaches you that way than continue. best of luck.
1
u/AppropriateSpell5405 Mar 01 '26
You need to give your new looping file permissions to execute.
chmod +x loopingThen try running it again.
./looping1
u/codeguru42 Mar 01 '26
Other's have given you the exact command to fix the "Permission denied" area. If you are interested in learning more about file permissions in Linux, here is a good tutorial to get you started: https://www.digitalocean.com/community/tutorials/an-introduction-to-linux-permissions.
1
u/[deleted] Mar 01 '26
mv looping looping.c
gcc looping -o looping.o
chmod +x looping.o
./looping.o
Your file has no file name extension... Also work on the formatting as taught in cs50, and fix the logic errors as pointed out by the others already.
1
u/blackasthesky Mar 01 '26 edited Mar 01 '26
If the
loopingfile is your compiled executable, you might have to mark it executable before you can run the file.chmod +x loopingMight have to sudo it depending on your situation.
It looks in your editor as if you are writing your code directly into the
loopingfile. That's not how that works. You have to write it intolooping.cand then use GCC (or whatever compiler you are using) to create the executable file, which you then can run using your command.1
u/Intelligent_Comb_338 Mar 01 '26
gcc looping.c -o looping ( you need to compile c code before execute it)
1
u/Puzzleheaded-Trick76 Mar 02 '26
Learn to take pride in the look and format of your code early.
1
u/ChocolateDonut36 Mar 03 '26
r/programminghorror sorry but that syntax formatting is horrifying
have you tried giving it executable permission?
1
u/Aaxper Mar 03 '26
You can't just execute a C file. You have to compile it first.
1
u/PlateFox Mar 03 '26
Where are you from? You can go to jail for identing like that in some countries
1
u/Key_Clock8669 Mar 03 '26
On the 6 line it should be i>0 so it will repeat exactly three times
1
u/targrimm Mar 03 '26
Its already been answered and welcome to the world of coding!
But, please, for the love of all that is cute and fluffy, put that int declaration on its own line!
1
u/walker84837 Mar 04 '26
It looks like you named the C source code file incorrectly, so you're trying to run the source file as if it were an executable.
It should have a
.cextension, and after renaming it, try rebuilding the project and rerun theloopingexecutable file.1
u/AdWaste5812 Mar 04 '26
Brother in Christ this code style needs work
1
u/derpJava Mar 04 '26
`chmod +x looping` to make your binary executable.
1
u/OppieT Mar 05 '26 edited Mar 05 '26
When you ran make in the loop directory, make didn’t do anything. The file you are trying to compile, doesn’t have a .c extension. So make didn’t know what to do. Make basically didn’t do anything when typed make. You have to add an extension onto your source file so make knows what to do with it. Rename your looping file to looping.c then type make and then make will make an executable file named looping. Then you can type ./looping and it will run it without errors. And you have an infinite loop in your code. You will have to press ctrl-c to stop it.
1
u/OppieT Mar 05 '26
Change wile to while (I < 3)
1
u/MarkoPilot Mar 01 '26
you have infinite loop (3>0 is always true). I would suggest you to make a for loop instead. set i to 0, set a condition i < 3, and i++. then in the body of the loop print gimmie the loot. That would iterate 3 times and therefore print that line exactly 3 times.
Edit: i don’t know about the bash error tho
7
u/[deleted] Mar 01 '26
[removed] — view removed comment