18

Today’s lesson in C programming:

DON’T use
system( “clear” );
in Mac OS...
Causes seg Fault in ur program when it is perfectly correct...

What happened was... a friend wanted help with C programming and had written this code... but it was getting seg Fault randomly... just random seg Fault when his code was correct...

I pinpointed the seg Fault to a printf statement but the statement was correct...

Off to search the issue I went, found out that flushing problems can occur in printf if u don’t use \n.
This happens randomly. Thought this might b the reason...
Went to a VM running Arch Linux and tested the code there... worked perfectly. No issues whatsoever.

From a distant memory I remembered some people discussing to never use system( “clear” ); since it causes issues.
Thought to remove that line from code, thinking it wouldn’t make any difference.
Well imagine my shock when the code worked fine after remove that freaking line...

M gonna blame this one on Mac OS since arch had no issues with it 😑😑

Now to find alternative to system( “clear” );

Damm it I spent 4-5 hours on this crap!!!!!!

Comments
  • 13
    Doesnt it fuck shit up bc its "clear" on unix, "cls" on windows and "fuckmeimrich" on mac?
  • 3
    "works on my machine"
  • 1
    @BindView
    Well that can b taken care of by macros to distinguish envs...

    And as for “fuckmeimrich”
    Come on... Mac OS is a pretty decent OS... πŸ˜…πŸ˜…πŸ˜πŸ˜
  • 0
    @calmyourtities
    Lol in this case, doesn’t πŸ˜‚πŸ˜‚πŸ˜‚
  • 8
    @Electrux gonorrhea is a decent illness but i wouldnt want it on my pc
  • 2
    @BindView πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚
    Point taken πŸ˜‚πŸ˜‚πŸ˜‚
  • 0
    Umm...
    Now I feel so stupid 😨😨😨😨

    I deallocated memory before using the variable which caused those seg faults... not because of system()...
    Although it is interesting to note that program didn’t seg fault when there was no system() call πŸ€”πŸ€”πŸ€”

    No idea....
    Well that’s why I love C 😍😍
  • 2
    @BindView lmao on the fuckmeimrich
  • 0
    @JonnyCodewalker I use clang...
    I’ll look for the flag thanks 😊😊
Add Comment