- Strength to Increase Rep
- +5
- Strength to Decrease Rep
- -1
- Upvotes Received
- 15
- Posts with Upvotes
- 14
- Upvoting Members
- 10
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
Re: There are three ways you can do this. The first one (and the not-so-basic one) is making use of [i]pointers[/i]. You can declare the cross-function variables inside main, and pass their addresses to the other functions, which, in turn, will modify the initial variables. Here's a sample, but unless you … | |
Re: We'd rather "f" your intelligence. Or the lack thereof. | |
Re: You could have a look over [url=http://zlib.net]zlib[/url], I think it's your best bet. | |
Re: [QUOTE=WaltP;1374475]Answering a C question with C++ is worthless. And using gets() and getch() is so wrong it's close to criminal. And do I really need to mention CODE Tags? The Member Rules are quite clear...[/QUOTE]What I find to be even more disturbing is the fact that this guy's created an … | |
This one is pretty strange (or at least I can't figure out what triggers it). I have the piece of code below, but there seems to be a bug with the second call of [icode]scanf[/icode]. It simply gets skipped. So the input should be something like [code] 10 3 fbfbfbfbfb … | |
Yes, it's yet another thread about implementing three basic operations (addition, subtraction and multiplication) on abnormally large numbers (> 100 digits). I've stored each digit inside an array of [icode]int[/icode]s, as the following piece of code illustrates [code=C] while((ch = getchar()) != EOL) a[len_a++] = ch - CHR; [/code] Now, … | |
Re: 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 [icode]countEven[/icode] function, you'd use the following [code=C] countEven(numbers); [/code] This is mainly because the name of the array is a pointer … | |
Re: You could create a header file. That is, take all the function definitions and prototypes from the first C file, put them in another .h file, and then use [icode]#include "header_file.h"[/icode] after you include the standard headers in your second C program. For example header.h [code=C] #include <stdio.h> void my_printf(const … | |
Re: You simple write its name and pass it the arguments. For example: [code=C] #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; } [/code] Going a step further and tokenizing the … | |
Re: It actually explicitly states that the assignment to [icode]i[/icode] is of [icode]unsigned long[/icode] type. Given the piece of code you've posted above, if you use something like [url=http://splint.org/]splint[/url] to check your code, you get a warning, stating that the assignment to [icode]i[/icode] is of incompatible type. There are few cases … | |
Re: If you're looking for the Assembly code and are using gcc, use the -S command line argument, and the output file will contain the code. | |
Re: I agree with Narue that [url=http://www.amazon.com/C-Programming-Modern-Approach-2nd/dp/0393979504/ref=sr_1_1?ie=UTF8&s=books&qid=1287055790&sr=1-1]C Programming: A Modern Approach[/url] is [i]the[/i] book for learning C. That's how I've learnt it, and I'm pretty satisfied with what I've got under my belt. Now, there's also [url=http://www.amazon.com/Without-Fear-Beginners-Guide-Makes/dp/0321246950/ref=sr_1_1?ie=UTF8&s=books&qid=1287055864&sr=1-1]C++ Without Fear[/url]. Ok, it's on C++, but I've found it to be quite the … | |
Re: Why [icode]scanf[/icode]? Are you familiar with [icode]getchar[/icode]? It's better suited for your needs. With [icode]getchar[/icode], it's as simple as [code] while(c = getchar() != '\n') [/code] Also, if I remember correctly, using a [icode]char[/icode] to check for EOF is not going to work, for [icode]char[/icode] is an unsigned data type, … | |
Re: 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. | |
Re: Because in C, const != "constant", but "read-only". That is, it is legal to initialize a const variable using [code] void f(int n) { const int m = n / 2; } [/code] but its value is dependent of n. So if we call f passing first 2 as argument, … | |
Re: No, you just have to change the linking. Before I tell you how to do this, though, I recommend you switch to Terminal + MacVim. Using an IDE in the beginning is overkill, as well as hiding certain aspects away from you. Now, after you create a new file (again, … | |
Re: [QUOTE=abhiab1991;1346887]1) Write a program to count the number of blank spaces in a given string. 2) Write a program to abbreviate a given string (e.g. if the input is Amar Akbar Anthony, the output will be AAA)[/QUOTE] 1. Go through the string, and increment a counter when you encounter a … | |
Re: The program is [b][color=red]wrong[/color][/b]. 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. [icode]scanf[/icode]). Next, you define [icode]main[/icode] as [icode]void main()[/icode], when it should be [icode]int main(void)[/icode]. Furthermore, you write [icode]scanf("%d", a);[/icode]. This is incorrect, as the … | |
Re: Was it really necessary that you bumped it? An [b]abstract data type[/b] is a data type whose representation is hidden from the client. A [b]heap[/b] is an array object representing an incomplete binary tree. A [b]stack[/b] is a set of items in which the element to be deleted is known … | |
Re: A good first step would be reading [url=http://en.wikipedia.org/wiki/Bus_error]the Wikipedia article[/url]. If you still don't manage to solve the problem, post some code here. | |
Re: The ## operator [i]pastes[/i] two [i]tokens[/i] together (this is why the operation is called the [i]token-pasting[/i] operation). In the above code, a function is defined as a macro, which, when given two arguments (var and 12, in our case), forms a single token (in our case, an [i]identifier[/i]), var12. | |
Re: A [i]parameter[/i] is used when defining/declaring (or prototyping) a function, and an [i]argument[/i] is passed (or given) when calling the function. In the example below, [icode]x[/icode] and [icode]y[/icode] are parameters, while [icode]a[/icode] and [icode]b[/icode] are arguments: [code] double average(int x, int y); /* Function prototyping; x and y are parameters … | |
Re: [QUOTE=Adak;1336005][...] you chose to declare new variables throughout the code. That's OK for some (few) newer compilers, but mine won't put up with it. If you declare your variables at the start of the function, then I can assist you further.[/QUOTE]Hmm... this could have been easier to fix w/ a … | |
Re: I think you [i]could[/i] install a GCC version for Windows through [url=http://www.cygwin.com/]Cygwin[/url]. When I was programming on Windows, I was using an IDE, [url=http://www.codeblocks.org/]Code::Blocks[/url]. | |
Re: I think you should learn the language's basics better (if you're 4/10), and then pick a project you're motivated about enough to finalize it. | |
Re: I think you need [url=http://www.dinkumware.com/manuals/default.aspx?manual=compleat]a reference[/url]. You can also check the header files on your own computer, installed by the compiler. | |
Re: 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 [b]attempt.c[/b] in your [i]home directory[/i] (the one with Movies, Music, and so on). Next, fire up … | |
Re: I can't really figure it out. Why do you (Ancient Dragon) keep posting C++ code in the C section? Am I missing something? | |
Re: Because you declare [icode]acName[/icode] as a [i]character [b]pointer[/b][/i]. That is, you cannot change individual letters. All you can do is have it point to another string. So you could write [code] #include<stdio.h> #include<stdlib.h> int main(void) { char *acName="hello daniweb"; *acName="H"; printf("%s\n",acName); } [/code] and the output would be [icode]H[/icode]. In … | |
Re: Well... the easiest way to avoid getting warnings is to write correct programs. Perhaps post some actual code. You can force gcc to hide warnings by compiling with the [icode]-w[/icode] flag. Note the lowercase. |