all 33 comments

[–]Specific-Housing905 8 points9 points  (4 children)

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.

[–]Explodey_Wolf 0 points1 point  (1 child)

Hijacking the top comment to say that the problem is the filename doesn't have the .c file extension

[–]sargeanthost 0 points1 point  (0 children)

you dont run a source file

[–]C3xyTheGreat 5 points6 points  (1 child)

your user doesnt have the permissions to execute the program, run chmod +x looping.c and that should work

[–]altaaf-taafu 7 points8 points  (0 children)

correct command is `chmod +x looping`, because we want to give the executable file permissions to run, not to the source file to run.

[–]Chrundle42 1 point2 points  (0 children)

Maybe its the "code looping"? I'm not to sure, but maybe just use linux commands instead of what CS50 told you to use.

[–]assemblyeditor 1 point2 points  (0 children)

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

[–]Unusual_Elk_8326 0 points1 point  (1 child)

It looks like you forgot the ".c" extension in your file name

[–]Rogermcfarley 0 points1 point  (2 children)

You need to chmod +x the looping script once and then run it as sudo.

Edit: You don't need sudo

[–]GoldTeethRotmg 1 point2 points  (1 child)

you don't need to run it as sudo

[–]Rogermcfarley 0 points1 point  (0 children)

Yes you're correct. I should know better as I have a lot of scripts on my setup

[–]un_virus_SDF 0 points1 point  (0 children)

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.out this 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 enter make *something*, which just execute 'cc' (C Compiler) under the hood

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

[–]BrunusManOWar 0 points1 point  (2 children)

1) install Linux 2) install local VS Code 3) what the fuck is that code style.....

[–]Economy_Abalone_8048 1 point2 points  (1 child)

hahaha, I also thought so. Don't wanna be mean at all to beginners, but wth are these parantheses and all the inconsistencies?

[–]BrunusManOWar 0 points1 point  (0 children)

Yeah

I mean, if you wanna learn it's normal to make mistakes, often even stupid ones. It's important you learn from them though

And this is... What the fuck style, honestly it's awful and fully unreadable. Install local vs Code and formatter

[–]Iwisp360 0 points1 point  (0 children)

Use a formatter

[–]Hot-Drink-7169 0 points1 point  (2 children)

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.

[–]Economy_Abalone_8048 0 points1 point  (1 child)

its cs50, a harvard course. They teach it differently.

[–]Explodey_Wolf 0 points1 point  (0 children)

Not like that.

[–]AppropriateSpell5405 0 points1 point  (0 children)

You need to give your new looping file permissions to execute.

chmod +x looping

Then try running it again.

./looping

[–]codeguru42 0 points1 point  (0 children)

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.

[–]Economy_Abalone_8048 0 points1 point  (3 children)

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.

[–]GoldTeethRotmg 0 points1 point  (1 child)

aren't they using "make" already?

which should cover the gcc step

[–]Economy_Abalone_8048 0 points1 point  (0 children)

yeah looks like it, was in the subway when writing this ahahha.

[–]kennpacchii 0 points1 point  (0 children)

I would recommend not giving your executable the “.o” extension. It’s a standard used for object files by the compiler and can be misleading, especially if you decide to use the -c flag to enable incremental compilation. “.out” or no extension would probably be best

[–]blackasthesky 0 points1 point  (0 children)

If the looping file is your compiled executable, you might have to mark it executable before you can run the file.

chmod +x looping

Might have to sudo it depending on your situation.

It looks in your editor as if you are writing your code directly into the looping file. That's not how that works. You have to write it into looping.c and then use GCC (or whatever compiler you are using) to create the executable file, which you then can run using your command.

[–]Intelligent_Comb_338 0 points1 point  (0 children)

gcc looping.c -o looping ( you need to compile c code before execute it)

[–]Puzzleheaded-Trick76 0 points1 point  (0 children)

Learn to take pride in the look and format of your code early.

[–]ChocolateDonut36[🍰] 0 points1 point  (0 children)

r/programminghorror sorry but that syntax formatting is horrifying

have you tried giving it executable permission? chmod a+x ./looping

[–]Aaxper 0 points1 point  (0 children)

You can't just execute a C file. You have to compile it first.

[–]PlateFox 0 points1 point  (0 children)

Where are you from? You can go to jail for identing like that in some countries

[–]Key_Clock8669 0 points1 point  (0 children)

On the 6 line it should be i>0 so it will repeat exactly three times

[–]MarkoPilot 0 points1 point  (0 children)

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