16 ms·
Quick, I need to parse a simple string; should I use scanf, fscanf, sscanf, scanf_s, fscanf_s, or sscanf_s?
by whatshisface 6y ago
Quick, I need to parse a simple string; should I use scanf, fscanf, sscanf, scanf_s, fscanf_s, or sscanf_s?
- typon 6y agoI don't understand C programmers are their seemingly utter inability to understand that C is actually not perfect and has tons of flaws, including a lot of complexity. Just because you're used to something doesn't make that thing not complex. Try teaching C to first year undergrads.
- kevinmchugh 6y agoC the language is really neat and exciting. C the ecosystem, including standard libraries, is a lot less compelling.
- reasonabl_human 6y agoLearned C in a class as a first year undergrad, it was great!
- smabie 6y agoI feel like undergrads learn C in their first year? Or at least I did (well I already knew it, but had a class that was in C).
- pjmlp 6y agoOn my university we learned C++, already with proper strings, vectors, in-house collection library. About 30 years ago.
- colonCapitalDee 6y agoI don't think C is the standard anymore. I'm graduating class of 2022 and my college taught Java to freshmen. My friends at different colleges mostly had the same experience, with a few using Python or C++
- pta2002 6y agoThis definitely varies by university. I had haskell and C on my first year, only had Java on the second.
- kjs3 6y agoI don't understand non-C programmers and their seeming utter inability to understand that C programmers are very aware of C imperfections and how to effectively deal with it, while being equally blind to the flaws and complexity in their own environments. I learned C as a first year undergrad.
- deleted 6y ago[deleted]
- ceceron 6y agoHave taught first year undergrads. Highly recommended experience: 5 stars. C definitely has many flaws, but I wouldn't say complexity is one of them. I wulld rather say it's too simple and one has to add the complexity all by themselves :D
- IQunder130 6y agoC was my first language as a first year undergrad, in mechanical engineering to boot. I think I came out of the experience just fine.
- monk_e_boy 6y agoI do (well to apprentices who are the same age and same level) I teach about 2 hours a week on c++ and they are fine. They pass the cpp institute exams (which are super hard!) So unless you actually DO teach then don't assume :)
- Smithalicious 6y agoI'm a final year undergrad and all my courses have used C except for the funcprog and OOP courses which used haskell and Java respectively. I've even been a teaching assistant for the very first programming course students take, so I have taught C to first year undergrads!
- timeslip1523 6y agoC is a lot easier to learn than Java, I know that much.
- spankyspangler 6y agoIs this supposed to be a trick question? All do virtually the same thing at their core, differing in where they take their input from and whether they are the C11 bounds checking variants. You can add all the v prefix variants too, doesn't really make things more difficult. You could have thrown in a bunch of functions from string(3), but even then... C string handling isn't great by any means, but it isn't vast or complicated either.
- whatshisface 6y agoYou can learn the C stdlib+system headers, but at that point you're doing something more or less equivalent to learning a high level language's features, and you're past the simplicity of K&R.
- spankyspangler 6y agoI'm not sure what you mean. C is a high level language. And yes it and standard library has obviously grown more complex than it was 50 years ago. It's small and easy to grasp the entire thing though, unlike most other more modern high level languages. That said, it's not entirely clear that matters too much. Almost any non-toy C project is going to be bringing in libraries outside libc, so you still need to go off and learn those if you want to work on a project. Doesn't really matter whether they're in the base language or not.
- pjmlp 6y agoReady for a random question out of the 200+ UB cases on the ISO C, or about a random feature from any C compiler?
- spankyspangler 6y agoI'm not sure if you replied to the wrong comment or not because it doesn't address what I wrote.
- 6y ago
- flukus 6y agoI type "man scanf" and check which one I need, I wish other languages had such accessible documentation.
- flohofwoe 6y agoHow often do you need to parse a string in an RTS game? If you need to do lots of string processing, C is simply not the right language. Thankfully one isn't forced to only learn a single programming language in life ;)
- krapp 6y ago>How often do you need to parse a string in an RTS game? Asset files, config files, shaders, obj files, CSV, XML, JSON, etc... it's not uncommon. Read the asset loading code in the posted game. For a language that doesn't even know what a "string" is, C applications tend to involve a lot of string parsing.
- GuB-42 6y agoYou write your own parser. Seriously, I don't use scanf that much in C. Most of the times, it doesn't do exactly what I want, or there is a more specialized alternative (ex: strtol). Also, generally, %s is bad, even the "safe" variant. For sscanf, it makes a copy, which is inefficient (if you are writing C, you want efficient code, right?) and you have to know the size in advance, and usually, you don't. Most of my string manipulation in C involves loops, pointers and a lot of in-place manipulation. It is tedious compared to other languages but it is very efficient, the reason I picked C in the first place.
- whatshisface 6y agoSo in the context of the larger debate, this answer falls in to the "C is simple, until you try to use it, at which point you start writing your own programming language in C to write your application in," category. In this perspective C is simple mainly because it's missing the already-written code that you have to benefit you in other languages.
- lal 6y agoI don't think any of this is close to fair. "C is simple" and "it takes some work to do stuff in C sometimes" aren't mutually exclusive, in fact the former necessarily implies the latter. C is simple, which means it doesn't have a pre-written obscure built-in or convoluted syntax to handle every possible thing you might want to do in the language. You're going to have to write some of the code in your project yourself. That doesn't mean C isn't simple. I don't think I have to get into why writing a string-parsing function isn't quite the same thing as writing your own programming language. And C has libraries too, to be fair. So if you prefer the "choose between 25 competing libraries that all provide the desired functionality but half of them are deprecated or don't work" workflow a lot of people are used to from C++ or whatever you can do that. Lots of people use libraries in C. In fact, as you might be aware, your OS's package manager doubles as the C language's third-party package manager. There has been plenty of "already-written C code," because it's a language that has been ubiquitous in computing for fifty years. I'm not sure where these same tired critiques bubble up from but I see them constantly and they don't make sense. There are a number of entirely valid and damning critiques to be made of the C ecosystem but "there aren't any libraries written in C" and "oh, so you say C is simple, huh? Have you tried using it?!" aren't among them. You're not going to be a 20 year veteran C developer and then suddenly just today learn about some obscure built-in, and that's what is meant by "simple" here, and that's a good thing.