As someone going through K&R, I'm a little confused about Exercises 1.6 - 1.8.
I can get both the sample programs in the book, as well as what I can come up with for the examples, to compile. However, once compiled, they run but don't actually appear to do anything.
This confused me too when I first started. So this book was written for C back in the Unix days it expects a unix like enviornment and for you to know the basics. This progam would then take input from a file which is the screen and end when you send the EOF character to the screen. I think my workaround since I knew c++ was to use some other character to signal end of input I used backquotes ( ` ). But the right way would be to just input the EOF might be ctr-D or something else I forget and it works as expected.
Matthew King
This thread is so dead. /g is for plebs
Justin Moore
gay
Chase Lee
I don't understand why this doesn't work #include #define DEFAULT 1 int main() { puts("I'll mimic everything you type~~"); char in=DEFAULT; while((in=getchar())!='\n') { int number_of_chars = 0; if (in!=' ') { number_of_chars++; putchar(in); } else { for (int i = 0; i
Jaxon Smith
Maybe you should stop putting pajeet in your namefield and people would take you a bit more seriously
Liam Ward
Control + c
Nathan Brooks
Which utility library to use for files+directory handling, allocators, data structures and threads when there's so many of them like qlibc, tbox, pjlib, glib?
Dylan Morris
What are you doing? Replacing all ' ' with '~'?
Josiah Martin
Bamp good to see a thread for C even in a place like Sup Forums. Sorry though, I don't have anything to show right now. jus bampin dawg
Josiah Reed
bump
Grayson Hall
Tell me again, why should I use C instead of C++?
Asher Sullivan
Anybody interested this is how you learn C in 2017:
>Intro - K&R as everybody starts with this. - A current operating system kernel style guide, to show you what declarations today should look like: man.openbsd.org/style (linux has a guide too) - CS:APP as a second intro, learning bits/binary/floating point/compilers/assembly level pointers ect ect. abebooks.com/servlet/BookDetailsPL?bi=19786293942 ($20 'global' edition)
>Intermediate - The Book 'Hackers Delight 2' to continue with CS:APP bitshifting tricks - This guide: matt.sh/howto-c - Critique of said guide: news.ycombinator.com/item?id=10908217 - This book to learn algorithm design in C: algorist.com/ (includes free lectures)
>Competent - This book, whatever latest edition: cert.org/secure-coding/publications/books/cert-c-secure-coding-standard.cfm? - Finally the Art of Software Security Assessment where you go back over every program you've ever written with both the CERT guide and this book in order to audit your old programs for vulnerabilities.
You can do this in about a year doing it everyday for say, 2 hours. I did.
Eli Davis
This, indeed Ctrl-D sends end of input signal.
There's a small book called "Unix Programming Environment" by kernighan everybody should read since it will teach you basics of unix which still works today such as Ctrl-D on any current Linux/BSD system (plus you learn filters like sed so can get better at vim if you choose that editor). There's also an interesting last chapter where they show you exactly how they did software development back then from scratch
Asher Martin
Fuck off with libraries. If you want to use libraries, go use another language.
This is C. Write your own library
Grayson Hughes
K&R is not a good first book. Read pages 20 - 23, it does not actually define what an array is.
Thomas Butler
>Thank you good sire How much do you earn now given that those stuffs are pretty damn good for one to become above average programmer and you said you did it.
However most people I know learned to program from K&R and just searched for information like 'what is an array' into youtube and got a video explaining it.
I work remote as a DbaaS "distributed systems programmer" which is almost entirely in Go and Ruby, but learning how C works inside out definitely helps me every single day to do things like optimize the Go GC, understand that division takes a lot of clock cycles and bitshifting is preferred, or understand Ruby better. After the security internship they offered me a F/T job as a Jr Consultant but by that time I was more interested in distributed systems, and it paid a lot more than what the local sec corp offered me. I live in a shitty country and my job pays almost $100k USD per year which is a fortune here, the local appsec job offered $55k/year in my currency which is monopoly money tier and was like 12hrs a day of work.
Brandon Rivera
I-Is C++ allowed?
Ian Gonzalez
C++ users are objectively the cutest
Alexander Hill
checked, and that's a pretty gud guide. I'm a somewhat seasoned C programmer and I pretty much agree. That and some resources I didn't know. How about modern C or whatever the name? I've heard good stuff about it though I've never read it. Also, Expert C should definetely be in that list.
Julian Ross
Y-you mean that user?
Parker Davis
Yeah, I wish I could be smart and cute enough to be a C++ programmer
Nathaniel Clark
Thanks user. You're cute too.
Xavier Harris
aaaaand it's a weeb thread
Josiah Edwards
I'm sorry
William Perry
user, it's a weeb website.
Carter Allen
still better than 99% of the threads in Sup Forums and nice repeated digits
main (){ inituart(); stdout = &uart_output; setupadc(); setupdigital(); while (1){ while (i < 1000){ if (PINB & _BV(PB0)){ lasthallread = 1; } if (!(PINB & _BV(PB0)) && lasthallread == 1){ rps++; lasthallread = 0; } _delay_ms(1); i++; } mph = round(rps*1.1244); rps = 0; i = 1; /*field too long*/ } }
Justin Taylor
Bitwise operators are the comfiest.
What does this program do? Read speed values and convert them?
Zachary Young
Hash tables or balanced trees?
Logan White
Should I start with C#, then move to C/C++?
I have good PHP, decent Python and limited Java knowledge. (With some BCPL but we won't go into that right now).
Angel Scott
In your code, number_of_chars gets initialized to zero each time after the while loop since you declare it there. Look at OP code.
Lucas James
>C# for Windows programming, Unity, Xamarin, i.e botnet >C for Linux programming and embedded system >C++ for everything else
Joshua Wood
>C++ for everything else
Landon Foster
Just accept the fact that the only reason you're not using C everywhere is money.
Gavin Mitchell
You use C to avoid the C++ programmers desu.
Carson Sullivan
But C++ programmers are the cutest?
Jaxon Parker
>namefag >hates C++ users
Adrian Wilson
If you're talking about then it's a malicious attempt to lure cuter user into hell.
Zachary Diaz
You can still write windows programs in C using the Win32 Api.
Evan Perry
Listen senpai, C++ isn't always shit. But it allows people to write shit code. And once people get into the habit of making shit code they become bad programmers.
My point is, you could use C++ just like C but with some extra features here and there. But that opens up for a lot of bad programmers to submit code to your projects... And suddenly your project isn't C with some convenient features from C++, it's a bloody full on C++ project using all of C++'s bad stuff.
I don't hate C++. I actually use it along side OpenGL and it works fairly well because I know what I'm doing. But doing big projects in C++ will in most case scenarios turn into a scary mess. Trust me senpai.
Lincoln Smith
I suggest we change the name of this thread to /gcc/ - General C Circlejerk pretty pls?
Caleb Baker
>says C++ has bad stuff >doesn't actually give examples of said bad stuff I am compelled by your words to stimulate the fatty neurons in my cranial organ, anonymous.
Owen Adams
If you want an example just look at the boost library.
C++ gives developers a false sense of security. Like using new and delete is safer than malloc and free, I swear some people actually believe that for some reason. C++ didn't even have a good string implementation until it was too late and a lot of software was written using it's own string type implementation making it hard to use two libs with each other for instance.
Also I get you're concern with me not giving any examples, I apologize for that. I'll do better in the future.
Another bad thing is the whole header and source file mess. I get why people had that in the beginning of C, obviously to save CPU cycles during compilation. Lib interfaces were not the only reason for header files back in the days. And yes you could technically use #pragma once or a simple if def in the source file and include them in other source files... But that's a "hack" and C++ was not meant for that.
You can have your opinion about #define in C but I think macros should always be avoided where possible. So while macros in C are sometimes unavoidable that's not the case in C++ and therefore the fact that they even support #define in C++ (Don't say muh backwards capability) is a bad practice and motivates very very strange code. Trust me, I've seen people macro "THEN" and "END" to "{" and "}".
Evan Reed
It looks to me like it's supposed to be incrementing nc until getchar returns EOF? Which I think only happens if you press a special key combination, like CTRL+Z I think it is on Windows? And then it prints out nc which is the number of characters read from stdin before EOF.
Not sure why it's using a double though, since it's only counting whole characters.
Joshua Gomez
> languages should force you to do things in one specific way
no they should not. C/C++ are more powerful languages than really any other and should give you the tools to deal with any situation. Removing defines would be like a paint company removing shit brown for being an ugly color.
Also nothing is stopping you from writing implementations in headers
Colton Jenkins
Ok thanks for the info but those seem like edge-cases or outliers desu. I've personally never seen any of the sort of stuff you mentioned but then again the only other person that uses C++ amongst my colleagues is a coauthor of mine who taught me C++ and everybody else either uses Fortran or Python.
Isaac Martinez
why use c when I can use thousands of c lines in one python line
Wyatt Nelson
it really is a whole different game. I haven't fucked around with embedded projects at all, but I feel like I will definitely need to know this shit when I start uni for CompE in 7 months. Bitwise operators are cute tho
Cameron Cruz
Is it a sin to generate C code from header files using Haskell to avoid having to write the library bindings for pforth manually? Currently working on the tool so I can get glew, glfw, openal, ect... bindings in pforth and can't be bothered to do it manually
Anthony Smith
C is only good for embedded programming, C++ has a wealth of libraries unlike C. Unless you want to re-invent the wheel, C is pointless for anything but small projects
Nicholas Moore
Wew don't bully C pls
Matthew Lee
C programming a modern approach it's still probably the best beginner's book, even though it's kind of outdated but there are other reference books for that.
Michael Fisher
What was the total time span from learning-to-getting-a-job it took you?
Joshua Murphy
C is an okay language, made horrible by the C standard, POSIX and portability fags. But god there's nothing I hate more than the C standard library and its ilk.
Sebastian Turner
pls rspnd
Levi Nguyen
>C is okay, made horrible by its literal definition What?