ok can you explain what a prototype is in simple terms for me plz.
ok can you explain what a prototype is in simple terms for me plz.
Look at this code...
If you actually try to call (i.e. use) a function before that function i defined, the compiler won't know if it's being called properly (i.e. that the right number and types of parameters are being passed and/or returned).
In order to let the compiler know what to expect, you simply add the function name with it's parameter types and return type (if any). So for a function called swap, which takes two pointers to integers, but returns nothing, you should add the line
void swap( int *, int * );
at some point after your #include's, and before main.
am i able to use scanf to read characters from input and then only print certain things back to output? How do i specify what i want it to print back out. For example if i only want it to print everything except an A or something? At this stage i only know how to scanf in one letter at a time and print the same letter back out again:
Code:#include <stdio.h> int main() { char a; scanf("%c", &a); printf("%c\n", a); }
this isnt working but am i on the right track with this?
Code:#include <stdio.h> int main() { char a[200]; while(a != '/0'){ scanf("%c", &a); } if(a != 'l' || a != 'L'){ printf("%c\n", a); } }
Best go to google.com and put scanf (or better) fgets into the search engine. You'll get everything you need from there.
It's always worth doing a quick search there before placing questions to the forum.
Ok i see how i use the gets, but how do i specify what i want it NOT to print out. Is it like what i did in the code in my last post or how so i do it. If you could point me to a tute that explains that.. cool, otherwise an example would be nice.
Heres the gets
Code:#include <stdio.h> int main() { char my_string[500]; gets(my_string); printf ("You typed: %s\n", my_string); return 0; }
>>Ok i see how i use the gets
Read these:
http://faq.cprogramming.com/cgi-bin/...&id=1043284351
http://faq.cprogramming.com/cgi-bin/...&id=1043284385
Once you have a line of text in an array, do something like:
Code:- get the string length (strlen) - run a loop, from 0 to length-1 - check each character against of unwanted character, and print it if it doesn't match len = strlen(input); for (i = 0; i < len; i++) { if (input[i] != 'W') putchar (input[i]); }
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
how come my or doesnt work?
Code:#include <stdio.h> int len; int i; int main() { char my_string[500]; gets(my_string); len = strlen(my_string); for (i = 0; i < len; i++) { if (my_string[i] != 'L' || my_string[i] != 'l') putchar(my_string[i]); } return 0; }
>how come my or doesnt work?
It works fine. But you probably mean to use &&.
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
I have had a look at what the FAQ has to say about strcmp() but i still dont really know how i use it, or even if its what i need to use. I need to be able to look at whole words and not just letters as i have got above. Can someone please show me an example of this.
i tried this:
but it wont work coz it only looks at individual characters.Code:if (my_string[i] != 'something') putchar(my_string[i]);
Don't bother too much with tutorials most of them tell you how to do everything the wrong way.
Go and buy a good reference book.
Thor's self help tip:
Maybe a neighbor is tossing leaf clippings on your lawn, looking at your woman, or harboring desires regarding your longboat. You enslave his children, set his house on fire. He shall not bother you again.
OS: Windows XP
Compiler: MSVC