949 Posted Topics

Member Avatar for bkoper16

First - that's not a program you posted, or a snippet of code that will run. Second - you NEED to use CODE tags. Click on the [CODE ] icon in the forum's editor and paste your code, between the tags it provides you. Third - you didn't give size …

Member Avatar for Perry31
0
187
Member Avatar for sing1006

* ALWAYS * use code tags on code forums. Forum software turns your code into html junk, otherwise - very hard to study. [CODE] #include<stdio.h> int main (){ int counter; int x; int product; counter=0; x=1; product=1; while (counter<5){ counter++; //this is C! product*=x; printf("x:%d *= product is: %d\n",x, product); …

Member Avatar for sing1006
0
123
Member Avatar for sing1006

You have to declare your variables, before you can use them. Generally, it's best to declare them, right at the top of the function they are used in.

Member Avatar for sing1006
0
336
Member Avatar for gahhon

This is one way: [CODE] #include <stdio.h> #include <stdlib.h> int main() { int i,j; char a[]={"1 22 33 444 5555 5 4 3 2 1"}; int n[10]; for(i=0,j=0;i<10;i++) { n[i] = atoi(a+j); while(a[++j]!=' '); printf("\n %d: %d", i, n[i]); } printf("\n\n\t\t\t press enter when ready"); (void) getchar(); return 0; } …

Member Avatar for gahhon
0
182
Member Avatar for niehaoma

I prefer where the numbers being tested are incremented by two, since no even number can be prime. Why test them at all? Only testing the odd numbers, cuts the work in half, straightaway. Also, I prefer a more concise coding. Not [CODE] rem = *num % *div; /* Calculate …

Member Avatar for hsetaknev
1
190
Member Avatar for Joey_Brown

You can do this with just one pair of nested loops, but I like using two to simplify it. The first pair of nested loops fills the char array a[][] with the correct values. The second pair of nested loops, prints them out. Clear out the array, to just spaces: …

Member Avatar for Joey_Brown
0
109
Member Avatar for berwick53

Is this for an assignment, or for real cryptographic use? It's very easy to do a simple encryption scheme yourself for an assignment, but it's quite another thing to devise a scheme to make it secure from attack. For real work, it's best to use a proven library - no …

Member Avatar for Adak
0
119
Member Avatar for atramposch

You need an outer "overall" loop (usually a for loop, let's say) [CODE] for(each number) { j=1; while(array[i] == array[i+j] { //because they're *sorted* ++j; } if(j > maxRepeats) mode = array[i]; } [/CODE] That's to get you started, you may have one off errors in it -- it's very …

Member Avatar for atramposch
0
101
Member Avatar for shanebond

The easiest way to do this might be to use an array of structs, where the struct was prototyped right below the include files, with members like int ID; char name[50]; etc. Then in main() create an array of those structs with struct student students[50] (for say, 50 students). Each …

Member Avatar for peter_budo
-1
716
Member Avatar for sallubhai

For your sorting functions, look at Wikipedia and search for Sorting algorithms. In general, if the function just goes through the data, one time, that would be your 0(n), complexity. Since obviously the complexity is directly a product of the number of items being handled, and nothing else. If it …

Member Avatar for sallubhai
0
209
Member Avatar for silver90

You need to first show us that you are working on this problem. So, what have you done to try to program this? Generally, posts with no attempt of code being posted, are skipped over. Post up what you've done, and be specific about what has you stumped. We want …

Member Avatar for Adak
0
115
Member Avatar for Joey_Brown

Be definition, you don't need code to add zeroes to the array - you are compressing it, not adding to it's length. Think along these lines: [CODE] for i=0, j=0; i< SIZE of array; assign a[j] to num1 set compress = 0 while j < SIZE if a[j] == num1 …

Member Avatar for Joey_Brown
0
111
Member Avatar for tastyTreeHUGGER

For printing the calendar for the month, you can use this pseudo code: [CODE]print your days of the week on a line with a couple spaces between each day day equals 1 for row=0, and each row less than 5, increment row if row is 0 for col=0 and each …

Member Avatar for tastyTreeHUGGER
0
304
Member Avatar for vinitmittal2008

[CODE] # include <stdio.h> void show(int (*)[3],int,int); int main() { int a[3][3]={1,2,3, 4,5,6, 7,8,9}; /* I would prefer the explicit: int a[3][3] = {{1,2,3},{4,5,6},{7,8,9}}; note the doubled braces */ show(a,3,3); return(0); } void show(int (*p)[3],int row,int col) /*I would use: void show(int p[3][3]) using the call show(a); Which emphasizes at …

Member Avatar for vinitmittal2008
0
10K
Member Avatar for Alerwiali

All two player games follow a very similar pattern: print introduction print instructions if user requests them initialize the cards, board, create any data structures needed to play the game, etc. Set options, read from a data file, all the "set up" stuff. print up a menu asking user if …

Member Avatar for Alerwiali
0
70
Member Avatar for chenlynn

If you can't do this, almost without thinking, then it's time you learned how. Really, this is the most basic logic and syntax to learn, after "Hello World". Get in there! ;) Anybody who'd do it for you, is doing you NO favors.

Member Avatar for Lesetja Frederi
0
158
Member Avatar for pappa j

Best idea for you would be to get all you can done, especially the parts that relate to the electronics. Direct your electronic questions to one of the electronic forums - (Google for that). Come back here for any questions you need answered having to do with C. I have …

Member Avatar for Adak
0
80
Member Avatar for Jollyyy100

This is the C forum. Do you believe that we don't deal with C problems? ;) One look around the place should have enlightened you on that point. Post your code, and describe what the problem is - tell us what it is that has you stumped.

Member Avatar for Adak
0
180
Member Avatar for berwick53

Strings in C are compared, using the include file string.h, and the strcmp() function. Here's how it works: The value returned by strcmp() tells whether the strings are: 0: means they are equal >0: means string1 is > than string2 <0: means string1 is < string2 [CODE]int variable = strcmp(string1, …

Member Avatar for Adak
0
199
Member Avatar for civirol02

@civirol02: I just answered this question in your other calendar display thread. Please, just one program per thread, or you'll wind up wasting a great deal of our time. The calendar display problem is solved.

Member Avatar for Adak
0
141
Member Avatar for civirol02

Your code will stay formatted properly, only if you click on the [CODE ] icon in the editing window, and paste your code right between the code tags that the editor gives you: [CODE ] <YOUR CODE GOES HERE> [/CODE ] Take a look at this. I couldn't quite grasp …

Member Avatar for Adak
0
416
Member Avatar for SpyrosMet

[CODE]if((strcmp(string1, string2))==0) string1 is equal to string2 or int num = strcmp(string1, string2); if(num==0) strings are equal else if(num < 1) string2 is greater than string1 //note the direction of //the < (big "mouth", facing string2) else string1 is greater than string 2 //string1 now has the "big mouth" of …

Member Avatar for Agnusmaximus
0
1K
Member Avatar for greenman78

What is the program solving? With the current logic, start with i, and see if you can narrow the range, a bit. Then repeat with j, and k. And what about N? Can it be brought down any? You should get a boost by redoing your arrays down to all …

Member Avatar for stokes1900
0
114
Member Avatar for ritesh2190

difficult! Algorithms are just general guides, they have to adjusted for every specific problem. There are programs that do this, for a very limited environment, and limited algorithms, but they are a very big project. Not something for the beginner.

Member Avatar for Anuradha Mandal
-1
4K
Member Avatar for Unidennn

When will tokens == NULL? It's the name of an array, it's not the contents of the any element of the array.

Member Avatar for Ancient Dragon
0
129
Member Avatar for Joey_Brown

What is the range of shorts on your system? My old compiler has a SHRT_MAX in the header file <limits.h>, that won't go to 360. If you make a habit of using the absolute minimal data type for your variables, you WILL get bitten by the "overflow" bug, a great …

Member Avatar for Joey_Brown
0
124
Member Avatar for nonshatter

Yes, malloc() returns NULL if the allocation failed. Did you include stdlib.h? Your cast of the pointer from malloc, is unnecessary in C, and will prevent the compiler from issuing an error regarding this oversight with stdlib.h. I don't believe 1000 char's is too much, but check the other variable …

Member Avatar for mitrmkar
0
116
Member Avatar for Alerwiali

There is no string in your program, at all. A bunch of letters are not a string, in C. They must have an end of string char, to mark the end of the string: '\0'. Only then are letters, elevated up to string status. A single char can never be …

Member Avatar for Adak
0
116
Member Avatar for subclass

I don't mean to be harsh, but it looks like you're doing the same thing as last week. It's time to put that shovel away, and quit digging a deeper hole, isn't it? You have a notion that you can do this, a certain way, and clearly, you can't. I …

Member Avatar for Adak
0
82
Member Avatar for MarounMaroun

Dude, you don't need to "open" argv - it's there, just waiting for you, courtesy of the C compiler. C automatically opens stdin, stdout, stderr, and creates argc and argv, when your program starts. (May not be an exhaustive list)

Member Avatar for sree_ec
0
148
Member Avatar for bufospro
Member Avatar for kimlong008

Kim, the arrangement of the data, makes this quite awkward. A normal arrangement might be: data/time string number1 number2 number3 ... etc. Which is very easy to retrieve from a file, put into an array, etc. It's VERY unusual to have a row of data that's over 450 char's in …

Member Avatar for kimlong008
0
112
Member Avatar for LiquidSolid

Imo, it's best to make a 2D array (static) for your data. That is your histograms, which you will fill in, before you print it. The code is a bit longer, but I like it because you can view one row of the array, as it's being made up, and …

Member Avatar for Adak
0
165
Member Avatar for berwick53

char string[50][50]; and use atoi() to convert a char string of digits, to an int. "alphanumberic to int", see? clever, no? ;)

Member Avatar for Adak
0
78
Member Avatar for hussamat

[B]Welcome to the forum, Hussamat![/B] ;) Now you trouble shoot it: 1) crate a list with 5 nodes and give them 1, 10, 20, 30, 40, values. 2) now try to add three values, working one at a time, until you know it's working correctly: 0: 25: 55: So you …

Member Avatar for abhimanipal
0
128
Member Avatar for MK1985

Welcome to the forum, MK1985! ;) You REALLY think we can diagnose the problem, without seeing the relevant code? [B][COLOR="Green"]<< ha ha ha ha ha ha that's hilarious! ha ha ha ha ha ha ha >>[/COLOR][/B]

Member Avatar for Adak
0
36
Member Avatar for littleCuteMaria

Strings are not compared with the == sign in C. Use strcmp(). When it returns 0, then the strings are equal.

Member Avatar for Ancient Dragon
0
123
Member Avatar for suma k

I don't know what you mean by "aging in operating system". If you want helpful answers, you need to be a lot more specific about the problem, and how you want to solve it, etc. Posting some or all of your code, and giving examples of input and desired output, …

Member Avatar for Adak
0
29
Member Avatar for poojabi

Multi merge sorting can be optimized to fit the architecture of a computer system, to produce an outstanding sorter. An example is the champion sorting program "Psort", which you can read more about by Googling it. In my testing, Binary insertion is better than the normal Insertion sort, and both …

Member Avatar for Adak
0
627
Member Avatar for jack223

You've replied to a thread that is 4 years old. I doubt the OP is still expecting an answer and will read your post. Start a new thread for your top, so it will get noticed, and get some answers. A comparison is made whenever you compare the value of …

Member Avatar for Adak
0
153
Member Avatar for lais90

You should know you can't print two things, at exactly the same time. How you change colors for your text, depends on your operating system. For windows, you should probably use the Windows API for this. If your compiler supports conio.h, you might be able to use that. If your …

Member Avatar for mitrmkar
0
714
Member Avatar for subclass

[B][COLOR="Red"]Welcome to the forum, Subclass![/COLOR][/B] ;) [CODE] /* dynamically creats a 2D array of pointers, in C */ #include <stdio.h> #include <stdlib.h> void allocate2D(double **dat, int nrows, int ncols); int main() { int i,j, rows, cols; double **dat; printf("\n\n\nEnter the number of rows and columns you want: \n"); scanf("%d %d", …

Member Avatar for subclass
0
237
Member Avatar for emmas4impact

I'd like you to check your book's index for rand(), or your man pages (if you're on Linux), or your help icon, if you're on Windows, search the forum for "rand()", or even Google "rand() in C". When you have a specific problem with your code, then post your code, …

Member Avatar for Adak
0
99
Member Avatar for jgehlot09

[QUOTE=jgehlot09;1192240]I want to generate 1billion random integer with no duplication, I dont know how do I allocate memory for such a huge amount of data.[/QUOTE] This is a trick question, isn't it? You've got a list of a billion unique random int's, stuffed in your back pocket, don'tcha? You're trying …

Member Avatar for Adak
0
114
Member Avatar for honberiz

The only function I would add, is a calculate() function, that would start with the while loop, and extend down to just before the fclose(InFile), line of code. Every variable you use in the while loop, needs to be brought down into the new function, as a parameter. It doesn't …

Member Avatar for Adak
0
158
Member Avatar for rashmideesh

Perhaps you TRIED to delete the phone number, and didn't really succeed, or the number is stored in memory. Or it's a Zombie phone number! ;) A thought: if you write data to a file, and the disk holding the file is set up for disk caching (the default for …

Member Avatar for Adak
0
171
Member Avatar for creeps

It's easier if you do your addition and subtraction on these long arrays, just as you were taught to do them, in school. Some people like to flip the numbers around, but I like just using char's, and starting with the highest element and decrementing the loop counter, as I …

Member Avatar for Shift-Stop
0
255
Member Avatar for Rahul.menon

The key to the game is that if you are at any time, needing to move a stack or substack, you will use the following: 1) if the stack/sub stack has an odd number of disks, you'll move the disk in question to the goal needle 2) otherwise, you'll move …

Member Avatar for Shift-Stop
0
228
Member Avatar for eviah

Would it be correct to move all the values higher than index 2, in your example, and then assign the 3 to array[2]? for example: int array[] = {3, 9, 7, 5, 11, 4, 8}; After sorting: {3,4,5,7,8,9,11} After placing the 3 in element 2 of the array: {4,5,3,7,8,9,11} <=== …

Member Avatar for eviah
0
201
Member Avatar for kangkan_14

First, Welcome to the Forum, Kanokan! ;) Second - it's a real pain to study code that isn't looking like code, because you didn't surround it with code tags (the code icon in the editor window gives you what you need to put your code between). Just because code will …

Member Avatar for N1GHTS
0
177

The End.