As Salem pointed out, 2D char arrays on the stack, are perfectly modifiable.
Of course there are differences passing an array with a different number of dimensions, to a function.
As Salem pointed out, 2D char arrays on the stack, are perfectly modifiable.
Of course there are differences passing an array with a different number of dimensions, to a function.
I'm sorry Adak. I have added some egg to my face to compensate.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
Ok thanks for your help everyone I'll try to implement what you've all said but I'll need to understand it first. I probably should have mentioned that I'm a begginer to C and I'm used to programming in Java where arrays are more easily manipulated. Even in java I would be considered a novice. The 2nd version of my program works but I can't understand why it returns -1 when it goes to the last else can anyone explain. I realise this may be trivial but I'm learning a lot from just trying differnt things.
Oh and my indentation wasn't great but I don't think I deserve a spanking.. i'll try harded next time I promise....
Edit: Ok just removed implicit main, inserted the 'const char *note' and the warnings are gone. I understand that using main() is the same as int main(void) but that the later is safer. Thanks. As for the scanf thing i'm looking into fgets. Thanks Again
Last edited by Taper; 12-07-2008 at 01:10 PM.
@MK27 - no problem. C is a complex language and nobody learning it, is going to be right all the time - certainly not me.
@Taper, C is a concise language. We don't use i = i + 1, we use ++i or i++. We get a lot of code, onto a single page, using good formatting and style.
I hate seeing code that has friggin' 15 letter-width tab indentation. The program frequently will "break the forum tables", making it almost unreadable.
Code:for(i = 0; i < MaxArraySize - 1; i++) { for(j = i + 1; j < MaxArraySize; j++) { if(strcmp(struct.name[i], struct.name[j]) > 0) { //etc. for(i = 0; i < MaxArraySize - 1; i++) { for(j = i + 1; j < MaxArraySize; j++) { if(strcmp(struct.name[i], struct.name[j]) > 0) { //etc. } } }
The first example (all part of a selection sort btw), is very likely to "break" the tables, and
has no more info than the smaller more C like, example below it.
In one screenful, with code like the second example, you can see a LOT of what's going on.
You can't do that with the first example, and I urge you to leave it behind ASAP. Nothing says "look at me riding my big wheel!" more, than code that is like that first example.
Teachers won't put up with it, and neither will anyone in the programming community or industry.
Last edited by Adak; 12-07-2008 at 01:24 PM.
Point taken mate. I will indent correctly before posting from now on.
Oh anyone any idea why, when the function calls itself again it doesn't return what the user entered?
Last edited by Taper; 12-07-2008 at 03:06 PM.
That's not quite true.
Take this example:
These are prototypes, but they are different. The first take an unlimited amount of arguments, the second takes none.Code:void foo(); void foo(void);
Let's take a look at another:
In this case, they are equal. The "void" part only matters in the prototype.Code:void foo () { } void foo(void) { }
And since you only define or implement main, it doesn't matter whether you put void into the parameter list or not.