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 3 1 2 3 3 4 5 6 4 7 8 9 10 [/code] but after I enter [code] 10 3 fbfbfbfbfb [/code] I get the (wrong) result, I do not get asked for the other 3 lines. Thanks in advance! P.S.: The variables' names are not in English :) …

Member Avatar
Member Avatar
+0 forum 2

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, when it comes to adding them, I add the [i](len_number - k)[/i]th digits of both numbers, compute their reminder and their quotient, and store the reminder on the [i]k[/i]th place of the [icode]sum[/icode] array. The following piece of code works nicely for, say, 132 and 32, but when I try …

Member Avatar
Member Avatar
+0 forum 7

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 loop, which does not seem to reach the EOF mark. So how should I go about detecting the end of file? Thanks in advance! [quote=K.N. King in C Programming: A Modern Approach on Page 588] Write a program that reads a series of phone numbers from a file and displays …

Member Avatar
Member Avatar
+0 forum 4

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 makefile for it, which compiles the program using GCC. As far as I've tried it, the program works fine, except for the fact that I've included the [icode]mword.c[/icode] file within the [icode]main.c[/icode] file, as I kept getting an [icode]undefined symbol[/icode] error which I couldn't solve. Therefore, I'd appreciate any help …

Member Avatar
Member Avatar
+0 forum 5

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 does it matter? Here are the three versions of the same idea (I guess the last version is the worst): Version 1, with curly brackets: [code=C] while(1) { if(1) { i++; } } [/code] Version 2, without curly brackets: [code=C] while(1) if(1) i++; [/code] Version 3, condensed version of the …

Member Avatar
Member Avatar
+0 forum 4

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 something of the form [icode]Enter day and reminder: Invalid Date[/icode], and I can't seem to figure out why. The same technique worked like a charm previously. [code=c] while(1) { if(num_remind == MAX_REMIND) { printf("-- No Space Left --\n"); break; } printf("Enter day and reminder: "); scanf("%2d", &day); if(day == 0) …

Member Avatar
Member Avatar
+0 forum 3

I've written the following binary search algorithm and it worked on [i]my[/i] tests. I want to know if there is something I'm missing, as this is the first time I try to write it, so give me a case in which it would fail, and I'll try fixing it. I know I don't have a sorting algorithm implemented (I will, shortly) and I know it doesn't work if the numbers are too big. [code=c] #include<stdio.h> int bsearch(int a[], int length, int n); int main(void) { int a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, n, result; …

Member Avatar
Member Avatar
+0 forum 3

Hello, I've been going through K.N. King's [url=http://knking.com/books/c2/index.html]C Programming: A Modern Approach[/url] and, after completing the first 10 chapters, I wanted to give my knowledge a try and write something I've always wanted to: a Hangman game. It turned out more of a "Mystery Word" game, as I haven't created the different phases of the hanging :) This being said, I'm looking for some code review. I want to know how I could have written it better, within the bounds of my current knowledge (no pointers or strings, no file input/output, no use of databases, to name the few constrains …

Member Avatar
Member Avatar
+0 forum 4

The End.