Search found 100 matches

by Grumpy Code Monkey
Fri Mar 19, 2010 4:17 pm UTC
Forum: Coding
Topic: Need some help in C
Replies: 8
Views: 920

Re: Need some help in C

I think the discussion about checking for newlines is a distraction; it sounds like the problem is that you're trying to read everything in with a single loop statement or something. Break up the reads according to how the data is structured in the file: /** * Get the number of players */ fscanf(in,...
by Grumpy Code Monkey
Sun Mar 14, 2010 3:50 am UTC
Forum: Coding
Topic: Is C++ Getting Phased Out?
Replies: 67
Views: 8160

Re: Is C++ Getting Phased Out?

It wouldn't surprise me if C++ were being phased out of intro CS classes; as teaching languages go, it's only marginally better than C, and C makes a lousy teaching language. As far as industry programming goes, C++ is still in fairly wide use (my current project is in C++). For certain uses, it hit...
by Grumpy Code Monkey
Thu Jan 28, 2010 4:48 pm UTC
Forum: Individual XKCD Comic Threads
Topic: 0694: "Retro Virus"
Replies: 164
Views: 42087

Re: "Retro Virus" Discussion

=sigh= Some days, I really miss VMS. The linux-heads forget that the old Morris worm played hell with Unix systems but didn't affect VMS or MPE or any IBM systems. Too bad Dijkstra didn't follow up his "GOTO Considered Harmful" paper with a "suid Considered Harmful", but, c'est l...
by Grumpy Code Monkey
Wed Jan 20, 2010 3:12 pm UTC
Forum: Coding
Topic: reg. expression help would be nice right about now
Replies: 5
Views: 647

Re: reg. expression help would be nice right about now

joshz wrote:Gorramit, I hate it when I spend that much time on a bug that's that simple.

Thanks!


IME, it's often the case that the really stupid bugs take the longest to find.
by Grumpy Code Monkey
Wed Jan 20, 2010 2:51 pm UTC
Forum: Individual XKCD Comic Threads
Topic: 0691: "MicroSD"
Replies: 140
Views: 37161

Re: "MicroSD" Discussion

When I was in college back in the mid-80's, one of my classmates brought in a nametag his father got at an IBM convention, and glued to the tag was a (failed) 1 MB memory chip that would have been part of a larger memory module. We spent the next couple of hours staring at it and just repeating &quo...
by Grumpy Code Monkey
Wed Dec 16, 2009 9:34 pm UTC
Forum: Coding
Topic: C or C++ for Linux coding?
Replies: 36
Views: 3979

Re: C or C++ for Linux coding?

C makes it easier to shoot yourself in the foot . C and *nix share a common heritage, and as a result most *nix system calls were originally written with C bindings in mind; systems programming on *nix simply feels more "natural" than other languages. While C++ has what I consider a better...
by Grumpy Code Monkey
Mon Nov 23, 2009 9:34 pm UTC
Forum: Coding
Topic: C: figuring out strcmp
Replies: 5
Views: 861

Re: C: figuring out strcmp

As written, what you have is fine. Are you sure the error is on the strcmp() call and not something else?

More code would help.
by Grumpy Code Monkey
Mon Oct 19, 2009 8:36 pm UTC
Forum: Coding
Topic: So, what is a job in programming like?
Replies: 20
Views: 5439

Re: So, what is a job in programming like?

My dad says that most programming jobs are probably going to be outsourced to places like China by the time I get out of college, but I want to hear from actually programmers who have a job doing this. From my perspective, the craze for outsourcing has died down a bit. Turned out not to be the silv...
by Grumpy Code Monkey
Mon Sep 28, 2009 8:37 pm UTC
Forum: Coding
Topic: Teach a C noob segfaults
Replies: 39
Views: 5245

Re: Teach a C noob segfaults

The "%c" conversion specifier tells scanf() to expect a corresponding argument of type char * (pointer to char), but you've passed a regular char. You need to pass the address of currentchar, like so: scanf("%c", &currentchar); What's happening is that scanf() is interpreting...
by Grumpy Code Monkey
Mon Aug 24, 2009 5:00 pm UTC
Forum: Coding
Topic: C macro - why doesn't this work?
Replies: 10
Views: 1613

Re: C macro - why doesn't this work?

Couple of things come to mind. First of all, are you compiling this as C89 or C99 (i.e., -ansi or -std=C99)? If the former, then your error message (expected primary expression before *) is probably due to mixing declarations and code; i.e., gcc is choking on the declaration of M because it comes af...
by Grumpy Code Monkey
Thu Aug 13, 2009 3:45 pm UTC
Forum: Coding
Topic: Function pointers in C.
Replies: 7
Views: 1700

Re: Function pointers in C.

The general syntax for a function pointer is T (*fp)() for a given type T. When you call the function, you can omit the dereference; i.e., fp(); is equivalent to (*fp)(); All you need to pass is the function identifier; you don't need to use &. In most contexts, the function identifier is implic...
by Grumpy Code Monkey
Wed Jul 15, 2009 7:40 pm UTC
Forum: Coding
Topic: C-strings
Replies: 22
Views: 1539

Re: C-strings

This is yet another data point supporting the fact that C and C++ really are two different languages (rather than one just being a sub/superset of the other). In C, the type of the string literal "123" is char[4], which in most contexts decays to char*. In C++, the type of the string liter...
by Grumpy Code Monkey
Wed Jul 15, 2009 3:36 pm UTC
Forum: Coding
Topic: C-strings
Replies: 22
Views: 1539

Re: C-strings

Also, you should never use NULL for the null character '\0'. They happen to have the same value on many platforms but there is no guarantee that will be true. Huh? I know that in C++, NULL is guaranteed to be 0. I presume the same would be true for C. NULL is guaranteed to compare equal to zero, an...
by Grumpy Code Monkey
Thu Jul 02, 2009 8:42 pm UTC
Forum: Coding
Topic: C versus C++
Replies: 20
Views: 2315

Re: C versus C++

Well, most of you "know what you're doing" folk seem to suggest learning C first, which makes sense, but I'll be taking a 2 year electronic engineering program in the spring. I have enough experience in hardware and math to stay alive, but my programming background is more or less nill, a...
by Grumpy Code Monkey
Wed Jul 01, 2009 12:58 pm UTC
Forum: Coding
Topic: C versus C++
Replies: 20
Views: 2315

Re: C versus C++

C is a much smaller language than C++, and somewhat more straightforward to learn (not to say it isn't chock-full of gotchas). C++ adds direct support for object-oriented programming (inheritance, polymorphism, encapsulation) as well as generic types (templates). You can sort-of write OO code in C, ...
by Grumpy Code Monkey
Mon Jun 29, 2009 2:41 pm UTC
Forum: Coding
Topic: Real Programmers
Replies: 52
Views: 4642

Re: Real Programmers

I worked with a couple of Real Programmers when I first started out (thankfully, not on the same projects). One of them really could not understand the point behind structured programming; it was a totally alien concept to him. A former co-worker of mine got to work on some C code written by a Real ...
by Grumpy Code Monkey
Mon Jun 29, 2009 12:50 pm UTC
Forum: Coding
Topic: Self taught Fortran?
Replies: 18
Views: 2118

Re: Self taught Fortran?

People still learn Fortran...? Isn't there anything else you could use? Fortran's still one of the best tools for certain kinds of scientific and engineering problems. And it's really not that bad a language, especially since the 1990 standard; the days of column-based layout and goto-driven contro...
by Grumpy Code Monkey
Tue Jun 23, 2009 9:51 pm UTC
Forum: Coding
Topic: C++: Getting Input from another program
Replies: 16
Views: 1973

Re: C++: Getting Input from another program

Here's an example of using sockets to communicate between programs on Windows. It may or may not be the solution you're looking for.
by Grumpy Code Monkey
Tue Jun 23, 2009 2:24 pm UTC
Forum: Coding
Topic: Design your ultimate coding keyboard.
Replies: 44
Views: 6767

Re: Design your ultimate coding keyboard.

InkL0sed wrote:I'd have one big button, which automatically wrote the program I wanted to at the time of pressing it.


This, with the added feature that pounding on it really hard will fix any bug.
by Grumpy Code Monkey
Mon Jun 22, 2009 1:50 pm UTC
Forum: Coding
Topic: Random number generation in C++
Replies: 27
Views: 4381

Re: Random number generation in C++

Call srand once at the beginning of your program. Also, using the % operator to scale your values is not recommended; it's better to multiply by a scaling factor. Here's a quick-n-dirty I womped up that illustrates both: #include <iostream> #include <ctime> #include <cstdlib> using namespace std; //...
by Grumpy Code Monkey
Wed Jun 17, 2009 12:12 pm UTC
Forum: Coding
Topic: Do you like documentation in code, and if so, how/when?
Replies: 44
Views: 7718

Re: Do you like documentation in code, and if so, how/when?

We have a coding standard where I work that requires a block of legalese at the head of the file, then a short statement describing the overall purpose of the class or module (in high-level English), then a short block at the head of each method describing the method's purpose, inputs, outputs, and ...
by Grumpy Code Monkey
Sat Jun 13, 2009 3:58 pm UTC
Forum: Coding
Topic: Switches vs. If-Then in C++
Replies: 18
Views: 1993

Re: Switches vs. If-Then in C++

A couple of points. If you are seriously worried about efficiency of an if/then vs switch statement, and thinking about how the compiler will implement a specific piece of code, you have problems. I simply didn't expect switches to be purely for making reading source code easier. I figured that sin...
by Grumpy Code Monkey
Sat Jun 13, 2009 3:31 pm UTC
Forum: Coding
Topic: How do you make you code/script files?
Replies: 34
Views: 2813

Re: How do you make you code/script files?

It is trivial to just save a file with an extension from an editor (heck, I sometimes do that (I use SciTE btw,)) but I was wondering if you used shell scripts to make files or had a nifty little program to do the job. No; what benefit does that offer over doing it the old-fashioned (and, as you sa...
by Grumpy Code Monkey
Wed Jun 10, 2009 3:35 pm UTC
Forum: Coding
Topic: Switches vs. If-Then in C++
Replies: 18
Views: 1993

Re: Switches vs. If-Then in C++

Not a whole lot to add to this except maybe some examples. If you're testing that x falls within a range of values, an if-else is clearly the way to go: if (x >= 100 && x <= 300) { do_something(); } else { do_something_else(); } as opposed to switch(x) { case 100: case 101: case 102: case 10...
by Grumpy Code Monkey
Wed May 27, 2009 6:35 pm UTC
Forum: Coding
Topic: Quick question about flow control!
Replies: 27
Views: 2266

Re: Quick question about flow control!

I've never really had any reason to optimize anything I've made, mainly because it's all been small stuff in the past. I guess I should start getting used to optimizing though. First rule of optimization: don't do it. Second rule of optimization: don't do it yet . First worry about getting it corre...
by Grumpy Code Monkey
Tue May 26, 2009 8:29 pm UTC
Forum: Coding
Topic: Quick question about flow control!
Replies: 27
Views: 2266

Re: Quick question about flow control!

Does this code take the same or close to the same amount of time to perform during runtime as the second code? The only way to know for sure is to profile both versions. I'm assuming all the timers are of the same type (time_t?); if so, you could clean things up a bit by using an array: time_t time...
by Grumpy Code Monkey
Mon May 18, 2009 2:53 pm UTC
Forum: Coding
Topic: Endiannessityness and Unions
Replies: 46
Views: 3107

Re: Endiannessityness and Unions

Uh, while we're on the discussion of unions. I'm just wondering...what are they used for? What benefits does someone gain from being able to interpret the same memory in several different ways? Officially, it's for if you're only going to use one at a time and need to save space. They're helpful wh...
by Grumpy Code Monkey
Mon May 18, 2009 2:30 pm UTC
Forum: Coding
Topic: How did you learn to program?
Replies: 60
Views: 6494

Re: How did you learn to program?

You, sir, name? wrote:Nothing is sadder than google queries like "C pointers + tutorial." They make baby You,Sir,Name? cry.


To be fair, crappy C tutorials predate Google by a fair margin. Hell, Herb Schildt made a living writing worthless C books a decade before the Web came along.
by Grumpy Code Monkey
Wed May 13, 2009 3:54 pm UTC
Forum: Coding
Topic: How did you learn to program?
Replies: 60
Views: 6494

Re: How did you learn to program?

Taught myself old-school BASIC on a TI-99/4A when I was in high school (ca. 1981-82). Took a computer literacy class my first semester in college (more BASIC, but on a DEC-20 -- ooooh), but that was to fill a hole in my schedule more than anything else. Didn't intend to major in CS, but after three ...
by Grumpy Code Monkey
Thu May 07, 2009 2:17 pm UTC
Forum: Coding
Topic: Fortran 77
Replies: 45
Views: 8020

Re: Fortran 77

So, I guess the question is "what's a printing character"? :P Anything other than whitespace (blank, tab, newline, etc.) and control characters (vtab, form feed, SOH, etc.), although some punctuation characters may not work (I'm not sure if ! in column 6 will be interpreted as a continuat...
by Grumpy Code Monkey
Wed May 06, 2009 11:16 pm UTC
Forum: Coding
Topic: Fortran 77
Replies: 45
Views: 8020

Re: Fortran 77

Update: So, I visited my professor and he fixxed one error (that the "IMPLICIT NONE" statement was not tabbed), and told me that the compiler is not picking up the "continuation lines" or some such. What is this exactly? From what he said, I gathered that these are lines that sh...
by Grumpy Code Monkey
Mon May 04, 2009 7:37 pm UTC
Forum: Coding
Topic: C programming - a good IDE?
Replies: 18
Views: 3353

Re: C programming - a good IDE?

villadelfia wrote:I know K&R, but what is H&S?


Harbison & Steele, "C: A Reference Manual", currently 5th edition. A good companion reference for K&R 2. It's been my primary reference for C programming since the 2nd edition (ca. 1986).
by Grumpy Code Monkey
Mon Apr 20, 2009 3:36 am UTC
Forum: Coding
Topic: Testing array elements in C
Replies: 7
Views: 1138

Re: Testing array elements in C

You can separate out the actual test as a function as well: int odd(int x) { return x % 2; } int even(int x) { return !(x % 2) } int any(int *arr, size_t arrSize, int (*test)(int)) { size_t i = 0; for (i = 0; i < arrSize; i++) { if (test(arr[i])) return 1; } return 0; } int main(void) { int array[10...
by Grumpy Code Monkey
Sun Apr 19, 2009 11:53 pm UTC
Forum: Coding
Topic: Graduating in a year, what do I need to learn?
Replies: 18
Views: 2031

Re: Graduating in a year, what do I need to learn?

PS: Please don't say depends on what you want to do. Unfortunately, it does. Software is simply too diverse a field to recommend any specific language or technology blindly. More important than learning any specific language or technology is the ability to learn new things quickly, and to be able t...
by Grumpy Code Monkey
Fri Apr 17, 2009 4:50 pm UTC
Forum: Coding
Topic: C programming - a good IDE?
Replies: 18
Views: 3353

Re: C programming - a good IDE?

When you say you don't know your system basics, what exactly do you mean? I ask because learning C may not actually be the right answer for you. As far as IDEs go, I have no real recommendation. A text editor, a compiler, a debugger, and K&R 2 + H&S 5 should be enough to get you started. Mos...
by Grumpy Code Monkey
Wed Apr 15, 2009 11:37 pm UTC
Forum: Coding
Topic: Learning Code
Replies: 27
Views: 2565

Re: Learning Code

See the thing is... i'm not even sure what coding really is. A series of lesser failures, eventually punctuated by success, immediately followed by more failures. Like second marriages and second children, it's the triumph of hope over experience. It's a way to make a living while hating life. Sorr...
by Grumpy Code Monkey
Wed Apr 08, 2009 3:06 pm UTC
Forum: Coding
Topic: Having trouble passing structures to functions in c
Replies: 11
Views: 949

Re: Having trouble passing structures to functions in c

(This kind of stuff is what people are referring to when they say that arrays and pointers in C are the same thing.) Pedant Alert: When an array identifier appears in any context other than as an operand to sizeof or &, it's type is implicitly converted from "N-element array of T" to ...
by Grumpy Code Monkey
Wed Mar 18, 2009 7:56 pm UTC
Forum: Coding
Topic: I just Dont get it... Logical operators...
Replies: 8
Views: 4098

Re: I just Dont get it... Logical operators...

Basics of bitwise operators: & - bitwise AND operator. For each bit in two input words, outputs a 1 if both input bits are 1, 0 otherwise. For example, 0101 & 0100 = 0100. | - bitwise OR operator. For each bit in two input words, outputs a 0 if both input bits are 0, 1 otherwise. For example...
by Grumpy Code Monkey
Wed Mar 18, 2009 12:34 pm UTC
Forum: Coding
Topic: dynamic linking in C
Replies: 16
Views: 1756

Re: dynamic linking in C

There is absolutely no reason for #including library.h in the program. It's never used, and that's the point.


Absolutely correct; it's there out of habit As you can probably tell, I don't use dlopen/dlsym all that much. Sorry for the confusing example.
by Grumpy Code Monkey
Tue Mar 17, 2009 9:32 pm UTC
Forum: Coding
Topic: dynamic linking in C
Replies: 16
Views: 1756

Re: dynamic linking in C

On the *nix side, there are the dlopen() and dlsym() facilities. Simple example: library.h: #ifndef LIBRARY_H #define LIBRARY_H extern int add(const int x, const int y); extern int sub(const int x, const int y); extern int mul(const int x, const int y); extern int divide(const int x, const int y); /...

Go to advanced search