- 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
55 Posted Topics
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. | |
Re: Try [code] digit[curpos] = (++digit[curpos]) % 10; [/code] The reason your code doesn't work is because it uses a [i][b]postfix[/b] increment operator[/i]. This means that the incrementation takes places [i]after[/i] the statement it can be found in has been executed. That is, the first piece of code below can be … | |
Re: 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 … | |
Re: Is [b]encrypted.txt[/b] in the same folder your program is in? Also, what operating system are you running? | |
Re: Adding to what has already been written, if you're looking for a more formal piece of information, I suggest you should [url=http://www.acm.uiuc.edu/webmonkeys/book/c_guide/2.12.html#printf]check here[/url]. | |
Elaborating on the title, I'm trying to complete an exercice in K.N. King's [i]C Programming: A Modern Approach[/i] which requires me to accomplish the task in the quote below. My idea works, but the program does not return control to the OS. I've nailed the problem down to the do/while … | |
Re: Mate, just look at your code and try to make some logic out of it. Here, I'll give you a hand. On [icode]line 7[/icode] you have a [i]closing[/i] brace ( [b]}[/b] ), but up to line 7, there are no [i]opening[/i] braces. Something must be wrong... On the next line, … | |
Re: Hmm... keeping the dictionary in an external file seems like the best approach to me. Correct me if I'm wrong. Regarding your first idea, it should work with a [icode]long int[/icode]. Correct me if I'm wrong again. | |
Re: You will have to implement your own data type and the operations you want to do with them. Or, you could use a library such as [url=http://gmplib.org/]GMP[/url]. EDIT: Sorry, Auroraomega and I posted at the same time. | |
Re: The difference, quite obviously, is the definition of [icode]main[/icode]. In the first version, the function is defined as [icode]void main()[/icode]. Therefore, it does not return anything. Furthermore, it takes an infinite number of arguments. The second version has the function defined as [icode]int main(void)[/icode]. It returns an [icode]int[/icode] value and … | |
Re: A very good first reading is [url=http://norvig.com/21-days.html]Teach Yourself Programming in 10 Years[/url]. | |
Re: A rule of thumb around here is that you post your existing code which you have problems with, or at least a pseudo-code. The sole piece advice which can be given is to store the parts of the date in separate variables which you then print in the new format. | |
Re: [quote]Yes, this is a known bug. Unfortunately, Apple has decided to make the conscious decision of not following the CSS standard on their mobile web browsers and handling fixed positioning differently than EVERY single other web browser in the world, including Safari for the desktop and every other mobile web … | |
Hello, I've learnt a bit more C since I posted [url=http://www.daniweb.com/forums/thread302037.html]the last code review thread[/url], so I've decided to rewrite the Mystery Word application, this time using strings, pointers and pointer arithmetic, and dividing the program into files (I've only got three of those). I've also created a very basic … | |
Re: [quote]Don't excessively optimize without good reason.[/quote] This, or "[i]Premature optimization is the root of all evil.[/i]" | |
Re: It's Objective-C, not C, and there is an extremely big difference between the two. Post it somewhere else, to a Mac/iPhone-related development forum, like [url=http://forums.macrumors.com]MacRumors[/url] or the programming-oriented [url=http://stackoverflow.com]StackOverflow[/url]. | |
I'm going through K.N. King's introductory [i]C Programming: A Modern Approach (2e)[/i] and every time I see the code in the book, I can't help but wonder what's the better way to write your code in the following situation. Should I use the curly brackets or not, and how much … | |
Re: Read lots of books, get involved in projects, get hands on, but, before anything, be sure you've read [url=http://norvig.com/21-days.html]Teach Yourself Programming in 10 Years[/url]. If you keep looking for information, you'll eventually know where to go from where you are. | |
I'm trying to validate a day of the month, so that if the user enters a negative value or a value above 31, the program prints an error message and prompts for another day. The code below doesn't work as expected. Instead, it gets caught inside an infinite loop, printing … | |
Re: [icode]%[/icode] is part of [i]conversion specifications[/i] such as [icode]%d[/icode] or [icode]%f[/icode]. Therefore, if you simply write [icode]%![/icode], it will be interpreted as requiring a second argument matching the data type associated to [icode]![/icode] (a so-called [i]conversion specifier[/i]). [icode]printf("Hello, World%!");[/icode] will print [icode]Hello, World![/icode]. Furthermore, it will display a formatting warning … | |
Re: Well... first of all, it should not come out 8, but 5. Going into your code, [icode]y[/icode] is not defined as a pointer, but it should, because what you are performing inside your code is [i]pointer arithmetic[/i]. Next, you are subtracting the address of the array, as [icode]x[/icode] actually means … |
The End.