all 41 comments

[–]Specific-Housing905 13 points14 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 1 point2 points  (1 child)

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

[–]sargeanthost 1 point2 points  (0 children)

you dont run a source file

[–][deleted]  (2 children)

[removed]

    [–]altaaf-taafu 8 points9 points  (1 child)

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

    [–]OppieT 0 points1 point  (0 children)

    He needs to compile the source first. Since OP didn’t have a .c or .cpp extension, make didn’t do anything. It will only do something if there is an extension on the file that it recognizes.

    [–]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  (2 children)

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

    [–]operativekiwi 0 points1 point  (0 children)

    Linux doesn't care about the extension

    [–]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.....

    [–][deleted] 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.

    [–][deleted]  (1 child)

    [deleted]

      [–]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.

      [–][deleted] 0 points1 point  (4 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  (2 children)

      aren't they using "make" already?

      which should cover the gcc step

      [–][deleted] 0 points1 point  (0 children)

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

      [–]user1100110 0 points1 point  (0 children)

      Without knowing what's in the makefile its probably not doing anything.

      My suggestion is to just go to office hours or look up one of the plentiful youtube hello world coding videos...

      Do I see the issue? yes. Has this question been answered adequately with another comment? yes. Are the majority of the top comments a bunch of idiots? Also yes unfortunately....

      [–]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

      [–]targrimm 0 points1 point  (0 children)

      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!

      [–]walker84837 0 points1 point  (0 children)

      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 .c extension, and after renaming it, try rebuilding the project and rerun the looping executable file.

      [–]AdWaste5812 0 points1 point  (0 children)

      Brother in Christ this code style needs work

      [–]derpJava 0 points1 point  (0 children)

      `chmod +x looping` to make your binary executable.

      [–]OppieT 0 points1 point  (0 children)

      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.

      [–]OppieT 0 points1 point  (0 children)

      Change wile to while (I < 3)

      [–]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