creeps 74 Junior Poster in Training

The main problem with your code is that the arrays should not be passed using the address operator (&). So if you wanted to pass the array to your countEven function, you'd use the following

countEven(numbers);

This is mainly because the name of the array is a pointer to its first element.

The second problem is that you've forgotten to put the j in your function's return statement.

Last but not least, the size and j variables inside main are not used, so you can get rid of them.

Here's how I'd write the above piece of code

#include <stdio.h>

int countEven (int *numbers)
{
    int even[7];
    int i=0, j=0;
    
    for(; i < 7; ++i)
        if(!(numbers[i] % 2))
            even[j++]=numbers[i];

    return j;
}

int main (void)
{
    int numbers[] = {2, 5, 10, 16, 31, 17, 30};

    countEven(numbers);
    
    printf ("%d\n", countEven(numbers));
     
    return 0;
}
ybsolar commented: there's a nice FOR loop. +0
creeps 74 Junior Poster in Training

You could have a look over zlib, I think it's your best bet.

dragonpunch commented: nice link +0
creeps 74 Junior Poster in Training

You simple write its name and pass it the arguments. For example:

#include <stdio.h>

int main(void) {

    /* printf *is* a function, and that's how we call all the other functions */
    printf("I am %d years old\n", 15);

    return 0;
}

Going a step further and tokenizing the function call, we get printf -- the function's name "I am %d years old\n" -- the function's first argument 15 -- the function's second argument

creeps 74 Junior Poster in Training

The program is wrong. Here's why:

First of all, you are not including a header file, therefore, you have no access to the I/O functions (i.e. scanf ).

Next, you define main as void main() , when it should be int main(void) .

Furthermore, you write scanf("%d", a); . This is incorrect, as the value of a must be changed by the function. Therefore, you must feed it a pointer to a: scanf("%d", &a); .

You don't need braces around the statements inside a case statement. So, instead of

case 1: {
printf("You are happy.");
break;
}

we write

case 1:
    printf("You are happy.");
    break;

Last but not least, your function is not returning anything. It should return 0 upon successful execution. So instead of getch(); , use return 0; .

creeps 74 Junior Poster in Training

Read a good book on it, but it might be a little too expensive for just file I/O. If you're looking for a reference, check the Dinkumware link in my signature.

creeps 74 Junior Poster in Training

A parameter is used when defining/declaring (or prototyping) a function, and an argument is passed (or given) when calling the function. In the example below, x and y are parameters, while a and b are arguments:

double average(int x, int y); /* Function prototyping; x and y are parameters */

int main(void) {

    int a = 10, b = 20;

    printf("%d\n", average(a, b); /* The function is called; a and b are arguments */
}

double average(int x, int y) { /* Function definition; x and y are parameters */

    return (x + y) / 2;
}
creeps 74 Junior Poster in Training

Because you declare acName as a character pointer. That is, you cannot change individual letters. All you can do is have it point to another string. So you could write

#include<stdio.h>
#include<stdlib.h>

int main(void)
{
char *acName="hello daniweb";
*acName="H";
printf("%s\n",acName);
}

and the output would be H .

In order to capitalize the first letter, you have to declare acName as a character array. You do this by declaring it as an array of characters, but a null character must be included in the characters count. That is, "hello daniweb" has 13 characters. You add the null character and declare an array of 14 characters. The version below does what you want.

#include<stdio.h>
#include<stdlib.h>
void main()
{
char acName[14] = "hello daniweb";
*acName='H';
printf("%s\n",acName);
}
Mouche commented: Nicely explained with example code +4
creeps 74 Junior Poster in Training

I think you need a reference. You can also check the header files on your own computer, installed by the compiler.

creeps 74 Junior Poster in Training

I haven't used Xcode in a while, but since you've got it installed, open TextEdit (unless you're comfortable with a command-line text editor, of course), write your program in there, and save it as attempt.c in your home directory (the one with Movies, Music, and so on). Next, fire up your Terminal (Applications -> Utilities -> Terminal.app) and type

gcc attempt.c -o attempt -Wall

Next, type in

./attempt

Now, to explain things a bit. Compiling the program is done, in the simplest form, using

gcc attempt.c

What this does is 1) call the gcc compiler, 2) pass it attempt.c as argument, and 3) produce object code in the file a.out (correct me if I'm wrong, but a stood for Assembly, right?).

If you compile it using the command above, you have to type

./a.out

in order to run the actual program. You can, of course, control the name of the output file. This is done by calling gcc with the -o flag (standing for output) and passing an output file name to it. That is, if we wanted the name of the executable to be attempt, we would use

gcc attempt.c -o attempt

Now we run the program using

./attempt

Compilation will fail if the compiler finds an error in your code, and you'll be notified. It won't fail, though, if your code generates warnings, but the actual program may not behave as intended, or even crash at some point during execution. If …

creeps 74 Junior Poster in Training

The problem in your approach is that your mind is stuck to thinking from left to right. Try thinking from right to left.

That is, compute d1, then d10, then d100. You also don't need the digit you've just stored anymore, so you're free to drop them. To give you an example, let's compute d1.

d1 = r % 10 /* Thinking from right to left, we first store d1 */
r /= 10 /* Now we drop the last digit of r, as we don't need it anymore */

/* By the time we've got all of d1, d10 and d100, r will be equal to r / 1000 */

I hope this is what you were asking and that it solves your problem. Good luck!

Adak commented: perfect answer +3
creeps 74 Junior Poster in Training

We'd rather "f" your intelligence. Or the lack thereof.

creeps 74 Junior Poster in Training

If conio.h appears in the book (windows-dependant), it is not a good book. My $0.2.

Ancient Dragon commented: Yes. +33
creeps 74 Junior Poster in Training

A very good first reading is Teach Yourself Programming in 10 Years.

Ancient Dragon commented: love it :) +33
creeps 74 Junior Poster in Training

% is part of conversion specifications such as %d or %f . Therefore, if you simply write %! , it will be interpreted as requiring a second argument matching the data type associated to ! (a so-called conversion specifier). printf("Hello, World%!"); will print Hello, World! . Furthermore, it will display a formatting warning at compilation.

abhimanipal commented: Nice .... I did not know this +1