- Strength to Increase Rep
- +7
- Strength to Decrease Rep
- -1
- Upvotes Received
- 20
- Posts with Upvotes
- 18
- Upvoting Members
- 14
- Downvotes Received
- 4
- Posts with Downvotes
- 4
- Downvoting Members
- 3
114 Posted Topics
Re: [QUOTE]We have to use other testing for primality, and I believe cse.avinash has explored using the Sieve of Eratosthenes, which I take it were also unsuccessful. [/QUOTE]You guys should take a look at [URL="http://www.scriptol.com/programming/sieve.php#c"]this[/URL].The second one is much more powerful than the first one(I'm totally amazed by the results). | |
Re: So , what's wrong with your program ? since we're not a psychic or in the mood of playing the"Guess what's wrong with my code" game, you have to tell us what exactly are you looking for. | |
Similar to echoserver, but this one handles multiple clients by forking the process. | |
This is a simple echo server that I've written while learning sockets programming. Compile the server and run it. You can connect to it using telnet like this: telnet localhost 1337 Disconnect the client by typing "/quit" without quotes. | |
This is a simple hangman game that I wrote using my beginner python skills. Though this game is playable, there must be lots of things I must've been doing wrong or the methods I'm using here may be not so pythonic. So I want some suggestions on how to improve … | |
Re: [QUOTE=MrNo;1704619][CODE]#include <stdio.h> #include <string.h> int main() { int count = 0; char *doc; FILE *inp; printf("Enter the file name: "); scanf("%s", doc); inp=fopen(doc, "r"); while((doc = fgetc(doc)) != EOF) { if (doc == ' ') count++; } fclose(doc); printf("%s contains %d words\n",doc,count); return 0; } [/CODE] So basically I'm a … | |
Re: And here's how you use strtok (you know... for future references). [CODE]#include <stdio.h> #include <string.h> int main(void){ char line[20] = "Process0 12 1"; // suppose this is the first line read by fgets char* delim=" "; char* result = NULL; result=strtok(line,delim); if(result != NULL) printf("process:%s\n",result);//store process in an array result=strtok(NULL,delim);//first … | |
If there's a list like below [CODE]s=['b','a','r','r','i','s','t','e','r'][/CODE] and if I tried to remove every 'r' from the list like this [CODE]>>> for x in s: if(x=='r'): s.remove(x)[/CODE] it gives the following result. [CODE]>>> s ['b', 'a', 'i', 's', 't', 'e', 'r'][/CODE] Why isn't the last 'r' removed from the list. | |
Re: [QUOTE]The program runs and compiles. When I enter the two words, it gives me a bunch of random stuff when printing[/QUOTE]That's because scanf is not used like this [CODE]scanf(x1,x2,MAXFORTHIS,stdin);[/CODE] [URL="http://en.wikipedia.org/wiki/Scanf"]click here[/URL] | |
Re: [QUOTE]anyone can tell me what this line does?[/QUOTE]clearly, it's returning the uppercase of the character given to the function.The first return statement only works if the condition cl>='a'(i.e.97 in decimal) AND cl<='z'(i.e 122 in decimal).If it does so then the second return statement is not executed, but if it does … | |
Re: [QUOTE]The case choices does not run after the input of the integers 0 or 1.[/QUOTE] You're missing '&'before 'choice' in your 'scanf' statement . [CODE]scanf("%d",&choice);[/CODE] and another(important!) thing,look at this [CODE]int number, integer,choice; int ArrayN[20]; for(i=0;i<20;i++) { printf("Enter 20 Integers\n"); scanf("%d", &number); printf("ArrayN[%d]=%d\n",i,number);//well, that's stupid! }[/CODE] You have to assign … | |
Re: When you compile your 'C' code, an object file is generated by the compiler. Such object files from each program(from the collection of programs) are build into a single binary(executabe) file by another program called linker. | |
Re: [QUOTE]Can you tell me why use size_t and not int for orig_len and rep_len?[/QUOTE] Using size_t instead of just plain int or unsigned int makes your code more portable since the size of int types vary across platforms. Also the above standard functions expect their third argument to be of … | |
Re: First of all, use code tags whenever you post any code.See that CODE thingy, click that and paste your well formatted code in between. There's no use of this `#include<conio.h> `in your code and why this `char studentanswer[30][30+1];` why not just declare it like this char studentanswer[30][31]; Since you're opening … | |
Re: [ICODE]'fflush(stdout)'[/ICODE] forces the data (if any)in the I/O buffer to be written to the screen .Including a '\n' character(if suitable) in the [ICODE]'printf'[/ICODE] itself also does the same thing.[CODE]printf("incorrect value\n");[/CODE]Remember that [ICODE]fflush[/ICODE] is only used with output streams.Calling [ICODE]fflush[/ICODE] with [ICODE]NULL [/ICODE]argument flushes all the opened streams. | |
Re: [QUOTE]This is a piece of code from some book.[/QUOTE]Is that [URL="http://www.daniweb.com/software-development/c/threads/389911/1679633#post1679633"]the same book[/URL] Narue told you to burn ? [CODE]int fun (const union employee *e); union employee { char name[15]; int age; float salary; };[/CODE]You should declare the union first and then the function 'fun'. [CODE]union employee{ char name[15]; int … | |
Re: The answer is in your error message [CODE]cc1: warnings being treated as errors test_cal.c: In function ‘calsum’: test_cal.c:20: error: control reaches end of non-void function[/CODE]Since function calsum is non-void(means returns something), so you should add a return statement. [CODE]return d;[/CODE] | |
Re: It's a very , very messy code.Here are few things that I saw, that could be potentially causing the problem. 1.You have named many things "Information".First the struct for book data[CODE]/*Structure for book information */ typedef struct Information { char subject [MAXIMUM_TITLE]; char author [MAXIMUM_AUTHOR]; int edition; int year; float … | |
![]() | Re: [QUOTE]The code compiles[/QUOTE]That totally amazes me.[QUOTE] but when I run the program it stops responding once it enters the while loop [/QUOTE]So there's a strong possibility that the problem lies on your while loop statement. [QUOTE][CODE] while (fgetc(inFile) != EOF) != NULL) {[/CODE][/QUOTE]'fgetc' returns EOF when read error occurs or … ![]() |
![]() | Re: [QUOTE][CODE]fflush(stdin); //clear the buffer???![/CODE][/QUOTE]Don't use [ICODE]'fflush'[/ICODE] with [ICODE]'stdin'[/ICODE],[URL="http://c-faq.com/stdio/stdinflush.html"]see why.[/URL]also [URL="http://c-faq.com/stdio/gets_flush2.html"]this[/URL]might be helpful. Either use [ICODE]getchar[/ICODE] after each call to [ICODE]scanf[/ICODE] to discard the '\n' from the input buffer or don't use scanf at all.There are [URL="http://docs.google.com/viewer?a=v&q=cache:V6IRXWslR5YJ:www.physics.ohio-state.edu/~ntg/780/handouts/interactive_input_in_C.pdf+how+to+take+inputs+interactively+in+c&hl=ne&gl=np&pid=bl&srcid=ADGEESiscFG8cYzt_lUxZk-m03JcLcXc46ILQ_roQLB6-39GuhhH1EHr_vn4eHVz6wZRzSOgJq3JkHiRbmJmOAM1OUT0mfpyZTeqn3qzq8dXgdXM5eUut8f1ddM-7LDs068yDWDu9lqq&sig=AHIEtbS9Sh6F_jZcWpfTiobG8o9XFEdAGg"]other solutions[/URL] for interactive inputs. ![]() |
Re: Well, I compiled your code and entered the number 119 and it printed out: " not a prime Prime number" Do you need help or just mocking us? Can you explain the algorithm you're using for this?(only if you're willing to, there's no pressure) | |
Re: What the ..? I mean, How the ...?[QUOTE]can anyone please tell me whats actually happening in this code. Seems to be as if incremented pointer is pointing to the next bit of same int.[/QUOTE] Why don't you try it in your compiler.did you?[QUOTE]Answer is 2,0[/QUOTE]So you did try it and … | |
Re: [QUOTE]Now, if anyone would be willing to assist me I would greatly appreciate it! [/QUOTE]I don't know what you need help with, since you have it all figured out.If you want us to write(or translate) your code for you, the forum rules wouldn't allow it. You have to use software … | |
Re: you forgot to use '&' in your scanf statement. [CODE]scanf("%d",&n);[/CODE] but what's the point of this [CODE]for(m=1;m<n;m++) for(t=1;t<=m;t++) { n=m*t; printf("%d,%d",m,n); }[/CODE] | |
Re: [QUOTE]no. it is not the expression is wrong. but the program enter the input itself. blank input. and it direct tell to input the correct answer before i get to input anything.[/QUOTE]This is a very common problem.I hope [URL="http://c-faq.com/stdio/scanfc.html"]this[/URL] will make things clear. If not, try to Google it yourself. | |
Re: just use [CODE]char* bus char* dest .../*and later*/ bus="single-decker" dest="taiping"[/CODE] | |
Re: [QUOTE][CODE]for(c_5=1; c_5<=10;c_5++) { for(c_6=c_5;c_6>=1;c_6--) printf(" "); for(c_6=10;c_6>=c_5;c_6--) printf("*"); printf("\n"); } printf("\n"); getch();[/CODE][/QUOTE] initialize c_5 to 0 instead of 1. [CODE]for(c_5=0; c_5<=10;c_5++)[/CODE] | |
Re: [QUOTE][CODE]int main( int argc, char **argv[] ) {//Wrong[/CODE][/QUOTE] [CODE]int main( int argc, char *argv[] ) {//right[/CODE] | |
Re: [QUOTE].for some reason sorting resets all entries to blank.Why is it doing that? I compare two entries, swap if necessary. Trying to figure out where that's failing.[/QUOTE]I compiled and ran your program, It works fine. In my opinion, in your 'DeleteEntry' function, try matching only the user's phone number, because … | |
Re: If you're using the variable val just to do this:[QUOTE][CODE]mov [val], ax add si,val[/CODE][/QUOTE]then there's no need to do so,just do it directly [CODE]add si,ax[/CODE] It's quite difficult to understand what you're trying to do, the information provided here is too little(not enough) and as far as your sample code … | |
Re: [QUOTE]It shows the same prompt multiple times[/QUOTE]That's because the 'printf' statement is inside the loop and you don't need to pass that 'i'.You can do like this: [CODE]int main (void)//this is more readable, isn't it? { int n, smallest=0, i=0; printf ("Enter a list of positive integars:\n");//printf outside the loop … | |
Re: [QUOTE=vedro-compota][CODE]if (!sizeof(stdin)) while (getchar() != '\n');[/CODE][/QUOTE][B]stdin[/B] is just a pointer to a [B]struct _iobuf[/B], so the [ICODE]sizeof(stdin)[/ICODE]will always return the size of a pointer variable(4 bytes). So your flushing mechanism [CODE] while (getchar() != '\n');[/CODE] won't even execute. [QUOTE=vedro-compota]- but this code 'll stop program when the input was empty … | |
Re: [QUOTE][CODE]void print_triangle_info(int area(), int perimeter()); void print_square_info(int area(), int perimeter());[/CODE][/QUOTE] Are 'area' and 'perimeter' functions? If not, why give parentheses after them.the correct form of prototyping will be: [CODE]void print_triangle_info(int, int); void print_square_info(int,int);//takes two integers as arguments and return nothing(void)[/CODE] and then their definitions [CODE]void print_triangle_info(int area, int perimeter) {//no … | |
Re: It's because of this line [CODE]int a[n];[/CODE] You cannot declare arrays like that. Here either 'n' should be initialized prior to declaring array [CODE]printf("Enter size:"); scanf("%d",&n); int a[n];[/CODE] or n should be replaced by some constant value. like this: [CODE] #define BUFFER 100 ... int a[BUFFER]; [/CODE] | |
Re: [QUOTE][CODE]#define EOF (-1)[/CODE][/QUOTE] You don't need to redefine EOF(already #[I]define[/I]d in "stdio.h"). [QUOTE][CODE]file = scanf("%d", &number);[/CODE][/QUOTE] You need to put this line in a loop to take consecutive inputs. [CODE]while((file = scanf("%d", &number)) == 1 && file!=EOF){ sum += number; sum_squares += number * number; ++n; }//repalces line 8 to … | |
Re: The only problem I'm seeing right now is the way you're passing filepath argument to fopen[CODE]file=fopen("E:\PROFILES.DAT","rb+");[/CODE] It should be like this: [CODE]file=fopen("E:\\PROFILES.DAT","rb+");[/CODE] | |
Re: [QUOTE=hugo17][CODE]int a,b; a = b;//[COLOR="Red"]bad practice[/COLOR][/CODE][/QUOTE] [QUOTE=hugo17][CODE]char c[2][2]; char d[3][3]; c = d;[/CODE][/QUOTE]Well?Why don't you try that in your compiler? the answer is no. you cannot do that with arrays. [QUOTE=hugo17][CODE]// or can you compare two arrays to get a true or false statement? if ( c == d)[/CODE][/QUOTE] Though … | |
Re: [QUOTE=Phillamon;1669659]Ola! I'm still kind of new with the whole assembly language and just need some help with this program i'm writing. What I want it to do is to ask a question -like for a number and then store that inserted number in a variable. And then test whether its … | |
Re: [QUOTE][CODE]#include <stdio.h> #include <string.h> #include <stdio.h> #include <stdlib.h> using namespace std; #include <iostream> [/CODE][/QUOTE]only need this one[CODE]#include <stdio.h>[/CODE] [QUOTE][CODE]if( sprintf (fileparam, "fall%d.dat", i) == true )[/CODE][/QUOTE] sprintf returns number of characters written(int) in the array 'fileparam' or a negative number if an error occurred not a Boolean. Your code when … | |
![]() | Re: You're opening the same file(handle) for reading and writing. [QUOTE][CODE]file = fopen (file2name, "r" );[/CODE][/QUOTE] it should be[CODE]write=fopen(file2name,"w")//"w" creates the file 'copy.txt' if it doesn't exist already[/CODE] |
Re: In addition, You can remove this line [CODE]#include <conio.h> //non- standard library,also not portable[/CODE] 'main' should always return int, like this:[CODE]int main(void)[/CODE] and return statement at the end.[CODE]return 0;[/CODE] add[CODE]fflush(stdout);[/CODE]after the printf statements,by doing that you'll force the output to be displayed on the screen even if the output buffer … | |
Re: [QUOTE]I now am having a problem entering values into the dynamic memory.[/QUOTE] It's not a good idea to ask for favors for every single problem you face. You should learn how to debug your own code at least. [QUOTE]Line 17-20 is a for loop to increment the variable 'i' so … | |
Re: You can do that like this: [CODE]setterm -bold on[/CODE]--> bold mode on [CODE]setterm -bold off[/CODE]-->bold off try:[CODE]man setterm[/CODE] or[CODE]info setterm[/CODE]for more information. | |
Re: Remove this line [QUOTE][CODE]int mainmenu();[/CODE][/QUOTE] from both 'main' and 'winmain'. and add a prototype of the function mainmenu at the beginning . [CODE]... int mainmenu(void); int main() ...[/CODE] | |
Re: [QUOTE=inagumi;1665066]Im using tasm xD In command prompt. what i mean is everytime i want to display it, it display the @,?,A,B,C etc. when the sum exceeds to 10,11,12,13,14 etc[/QUOTE] Instead of explaining what you meant, had you posted your code here, you may have already got the solution. | |
Re: [QUOTE=annonymous21]i found that if i do not add a newline char to the end of fprintf to stdout, it will hang. But if i add the \n it works...[/QUOTE] fprintf doesn't print the message until the output buffer is full. To make the prompt to be displayed immediately, you should … | |
Re: [QUOTE][CODE]fp = fopen("tmp","r");//in this line fd turns to be 0[/CODE][/QUOTE] I didn't see any fd, there. [QUOTE][CODE]freopen("tmp","w",stdout);[/CODE][/QUOTE] Wouldn't it be a good idea to save it's return value(i.e. file handle) somewhere else to use it later. [QUOTE][CODE]close(stdout);[/CODE][/QUOTE] 'Close' takes an integer representing filehandle to the opened file. [QUOTE][CODE]fgets(buf,100 , fp) … | |
Re: [QUOTE=Tenjune]I'm testing this sample fast food chain program and my problem is every time I select the order the resulting price is like Php895764796364227741000000000000000.0000[/QUOTE] Your code is incomplete. You're trying to print the resulting price 'TP' without assigning any value to it. [CODE]printf("\nMay I take your order?\n"); scanf("%d", &choice); /* … | |
Re: [QUOTE][CODE]void main(void)[/CODE][/QUOTE] 'main' should always return an 'int'(see [URL="http://www.daniweb.com/software-development/cpp/threads/337749"]here[/URL]or [URL="http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?id=1043284376&answer=1044841143"]here[/URL]or [URL="http://users.aber.ac.uk/auj/voidmain.shtml"]here[/URL],...the list will go "beyond infinity" ). It's better not to use labels and goto statements as they make your program's control flow hard to follow[QUOTE][CODE]goto add;[/CODE][/QUOTE](see [URL="http://c-faq.com/style/stylewars.html"]here[/URL]).Here in your case you can use 'continue' statement, it will do the … | |
Re: [QUOTE=vedro-compota]but what about point between words - it's feature of objective programming , but original c is functional language , isn't it? if "isn't" how can it be implemented without objective style? [/QUOTE] Well, WNDCLASS is a structure defined in 'windows.h' and the contents of a structure are accessed with … |
The End.