Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming

Reply
 
LinkBack Thread Tools
Old 05-17-09   #1 (permalink)
Nom nom nom..
 
Blizzie's Avatar
 
intel nvidia

Join Date: Jul 2007
Location: California, USA
Posts: 2,979

Rep: 254 Blizzie is a proven memberBlizzie is a proven memberBlizzie is a proven member
Unique Rep: 209
Trader Rating: 2
Default (Edit) Recursive bubble sort help

Edit: Look at post #9



I'm trying to write a Fibbonacci function and this is what I have? I'm trying to set argv to equal to a variable but I don't know how. Anyone?

The program will compute the Fibbonaci number supplied by argv[3].



Code:
void Fibonacci(int number, char **argv)
{
	int n = argv[3];
	int sum;
	
	if (n == 0 || n == 1)
	{
		return 1;
	}
	else
	{
		sum = Fibonacci(n-1) + Fibonacci(n-2);
		return sum;
	}
}
__________________

Blizzie
Κατεψυγμένα Στερεά

Hold on to the calm before the storm comes



System: Aeon
CPU
Q6600 G0 | 3.6 GHz @ 1.36v | 1.2375 VID
Motherboard
Foxconn BlackOps X48 | Quantum Force
Memory
2x2 GB DDR3 OCZ Reapers HPC | 1.6 GHz 7-7-7-24
Graphics Card
EVGA GTX 260 Core 216 | 702/1404/1242
Hard Drive
500GB WD5000AAKS | 1TB WD1001FALS
Sound Card
Creative X-Fi XtremeGamer
Power Supply
Corsair CMPSU 550VX 550W
Case
Antec Nine Hundred
CPU cooling
Zalman CNPS9700
GPU cooling
Stock
OS
Windows 7 Professional x64
Monitor
Envision 22 in. LCD Widescreen | 1680x1050

Last edited by Blizzie : 05-18-09 at 04:21 AM
Blizzie is offline Overclocked Account   Reply With Quote
Old 05-17-09   #2 (permalink)
Case Modder
 
Spotswood's Avatar
 
Join Date: Jul 2008
Location: New Hampshire, USA
Posts: 236

Rep: 46 Spotswood is acknowledged by some
Unique Rep: 39
Trader Rating: 0
Default

Use atoi() to convert a string into an int:

Code:
int n = atoi(argv[3]);
__________________
Rich
Custom Wooden Case Builder
Overclock.net Mod of the Month
Spotswood is offline   Reply With Quote
Old 05-17-09   #3 (permalink)
Nom nom nom..
 
Blizzie's Avatar
 
intel nvidia

Join Date: Jul 2007
Location: California, USA
Posts: 2,979

Rep: 254 Blizzie is a proven memberBlizzie is a proven memberBlizzie is a proven member
Unique Rep: 209
Trader Rating: 2
Default

Ah I see, thanks. Now I have:

Code:
int Fibonacci(int number, char **argv)
{
	int n = atoi(argv[3]);
	int sum;
	
	if (n == 0 || n == 1)
	{
		return 1;
	}
	else
	{
		sum = Fibonacci(n-1) + (Fibonacci(n-2);
		return sum;
	}
}
It gives me error: too few arguments to function `Fibonacci' when I compile. In reference to this line:
Code:
sum = Fibonacci(n-1) + (Fibonacci(n-2);
__________________

Blizzie
Κατεψυγμένα Στερεά

Hold on to the calm before the storm comes



System: Aeon
CPU
Q6600 G0 | 3.6 GHz @ 1.36v | 1.2375 VID
Motherboard
Foxconn BlackOps X48 | Quantum Force
Memory
2x2 GB DDR3 OCZ Reapers HPC | 1.6 GHz 7-7-7-24
Graphics Card
EVGA GTX 260 Core 216 | 702/1404/1242
Hard Drive
500GB WD5000AAKS | 1TB WD1001FALS
Sound Card
Creative X-Fi XtremeGamer
Power Supply
Corsair CMPSU 550VX 550W
Case
Antec Nine Hundred
CPU cooling
Zalman CNPS9700
GPU cooling
Stock
OS
Windows 7 Professional x64
Monitor
Envision 22 in. LCD Widescreen | 1680x1050
Blizzie is offline Overclocked Account   Reply With Quote
Old 05-17-09   #4 (permalink)
Linux Lobbyist
 
FearMeansControl's Avatar
 
intel nvidia

Join Date: Aug 2007
Location: Wrong Island, NY
Posts: 1,419

Rep: 94 FearMeansControl is acknowledged by some
Unique Rep: 83
Trader Rating: 2
Default

edit: oops! nvm
__________________
Quote:
Originally Posted by nitteo View Post
The biggest contribution we can make F@h is by spreading the word. A farm of 100 people will last longer than a farm of 100 GPUs.
(450x8) (417x9) (425x9)

System: Jesus PC v5.3
CPU
Q6600
Motherboard
Gigabyte X38-DS4
Memory
OCZ PC-8000 4x2 GB
Graphics Card
Quadro FX-4600 & FX-1400
Hard Drive
3x1200.12 500GB RAID 0, 2x7200.11 500GB RAID 1
Sound Card
Presonus Firepod + Yamaha HS-5M's
Power Supply
OCZ StealthxStream 600W
Case
RocketPwn
CPU cooling
Fuzion v2, mcw-30, GTX 360, D5, CD Waterfall Res.
GPU cooling
Stock, re-applied with AS5
OS
Gentoo, XP x64
Monitor
Samsung Syncmaster 2253LW + 2x17" LCD's
2 Million+ Folding at Home points

Last edited by FearMeansControl : 05-17-09 at 06:51 PM
FearMeansControl is offline   Reply With Quote
Old 05-17-09   #5 (permalink)
Nom nom nom..
 
Blizzie's Avatar
 
intel nvidia

Join Date: Jul 2007
Location: California, USA
Posts: 2,979

Rep: 254 Blizzie is a proven memberBlizzie is a proven memberBlizzie is a proven member
Unique Rep: 209
Trader Rating: 2
Default

Well I have this now:

Code:
int Fibonacci(int n)
{
	int sum;
	
	if (n == 0 || n == 1)
	{
		return 1;
	}
	else
	{
		sum = (Fibonacci(n-1) + (Fibonacci(n-2));
		return sum;
	}
}
And this is part of my main()

Code:
int main(int argc, char **argv)
{
	int number = atoi(argv[3]);
	int Fib;

....


		if (argv[1][1] == 'f')
		{
			Fib = Fibbonacci(number);
			printf("Fibonacci number: %d", Fib);

....
For some reason it gives this:
error: syntax error before ';' token

In reference to:
sum = (Fibonacci(n-1) + (Fibonacci(n-2));
__________________

Blizzie
Κατεψυγμένα Στερεά

Hold on to the calm before the storm comes



System: Aeon
CPU
Q6600 G0 | 3.6 GHz @ 1.36v | 1.2375 VID
Motherboard
Foxconn BlackOps X48 | Quantum Force
Memory
2x2 GB DDR3 OCZ Reapers HPC | 1.6 GHz 7-7-7-24
Graphics Card
EVGA GTX 260 Core 216 | 702/1404/1242
Hard Drive
500GB WD5000AAKS | 1TB WD1001FALS
Sound Card
Creative X-Fi XtremeGamer
Power Supply
Corsair CMPSU 550VX 550W
Case
Antec Nine Hundred
CPU cooling
Zalman CNPS9700
GPU cooling
Stock
OS
Windows 7 Professional x64
Monitor
Envision 22 in. LCD Widescreen | 1680x1050

Last edited by Blizzie : 05-17-09 at 07:03 PM
Blizzie is offline Overclocked Account   Reply With Quote
Old 05-17-09   #6 (permalink)
Case Modder
 
Spotswood's Avatar
 
Join Date: Jul 2008
Location: New Hampshire, USA
Posts: 236

Rep: 46 Spotswood is acknowledged by some
Unique Rep: 39
Trader Rating: 0
Default

What's right before the ';'?
The compiler is complaining about the unbalanced parenthesis.
__________________
Rich
Custom Wooden Case Builder
Overclock.net Mod of the Month
Spotswood is offline   Reply With Quote
Old 05-17-09   #7 (permalink)
Nom nom nom..
 
Blizzie's Avatar
 
intel nvidia

Join Date: Jul 2007
Location: California, USA
Posts: 2,979

Rep: 254 Blizzie is a proven memberBlizzie is a proven memberBlizzie is a proven member
Unique Rep: 209
Trader Rating: 2
Default

Quote:
Originally Posted by Spotswood View Post
What's right before the ';'?
The compiler is complaining about the unbalanced parenthesis.
__________________

Blizzie
Κατεψυγμένα Στερεά

Hold on to the calm before the storm comes



System: Aeon
CPU
Q6600 G0 | 3.6 GHz @ 1.36v | 1.2375 VID
Motherboard
Foxconn BlackOps X48 | Quantum Force
Memory
2x2 GB DDR3 OCZ Reapers HPC | 1.6 GHz 7-7-7-24
Graphics Card
EVGA GTX 260 Core 216 | 702/1404/1242
Hard Drive
500GB WD5000AAKS | 1TB WD1001FALS
Sound Card
Creative X-Fi XtremeGamer
Power Supply
Corsair CMPSU 550VX 550W
Case
Antec Nine Hundred
CPU cooling
Zalman CNPS9700
GPU cooling
Stock
OS
Windows 7 Professional x64
Monitor
Envision 22 in. LCD Widescreen | 1680x1050
Blizzie is offline Overclocked Account   Reply With Quote
Old 05-17-09   #8 (permalink)
Security Sleuth
 
Pooping^fish's Avatar
 
intel nvidia

Join Date: Jul 2007
Location: egypt
Posts: 1,266

Rep: 67 Pooping^fish is acknowledged by some
Unique Rep: 62
Trader Rating: 3
Default

Quick example, *didnt test it* but should work fine.

Code:
unsigned long int Fib(unsigned long int x, unsigned long int y)
{
         unsigned long int z = x + y;
         printf("%d + %d is %d\n", x, y, z);
         Fib(y, z);
}

void main(int argc, char *argv[]) 
{
if(argc != 3) {
     printf("%s <num1> <num2>\n", argv[0]);
     return; }

Fib(atoi(argv[1]), atoi(argv[2]));

return;
}
Recursive example. No delimiter for run here, and depending on how high you want to go youll need to change the var types appropriately.

Edit-I remember doing this with Hobo back when he was teaching me C++. Good times.
__________________
Quote:
"O, hai! Want som pRon? Dwnlod ths kodk frst. Its teh bst pRonz ever, we prmis." -GibbyGano
Proud Member of the Linux Gaming Community
I am your friend.

System: ragequit
CPU
Q9550 4ghz @ 1.25v
Motherboard
Asus Max 2 formula
Memory
OCZ LV blade 1:1 950mhz
Graphics Card
8800gtx 610/1ghz
Hard Drive
7200.10 250gb
Sound Card
X-FI Extreme Music
Power Supply
750w Toughpower
Case
Lian li pc-65
CPU cooling
TRUE
GPU cooling
stock
OS
leetlinucks
Monitor
24" Westy
Pooping^fish is offline   Reply With Quote
Old 05-18-09   #9 (permalink)
Nom nom nom..
 
Blizzie's Avatar
 
intel nvidia

Join Date: Jul 2007
Location: California, USA
Posts: 2,979

Rep: 254 Blizzie is a proven memberBlizzie is a proven memberBlizzie is a proven member
Unique Rep: 209
Trader Rating: 2
Default

Alright. I got everything working but now I need to implement a bubble sort that's recursive. I looked up how to do a bubble sort on Google but I'm confused on how to make it recursive.

Can someone point me in the right direction or explain the algorithm a bit?

Code:
void bubbleSort(int *array, int length)
{
  int i, j, temp;
  int test; /*use this only if unsure whether the list is already sorted or not*/
  for(i = length - 1; i > 0; i--)
  {
    test=0;
    for(j = 0; j < i; j++)
    {
      if(array[j] > array[j+1]) /* compare neighboring elements */
      {
        temp = array[j];    /* swap array[j] and array[j+1] */
        array[j] = array[j+1];
        array[j+1] = temp;
        test=1;
      }
    } /*end for j*/
    if(test==0) break; /*will exit if the list is sorted!*/
  } /*end for i*/
      
}/*end bubbleSort*/
http://www.codecodex.com/wiki/index....=Bubble_sort#C


I have a .txt file that contains lines of numbers. Do I have to create an array and feed in the numbers using fscanf in a while loop?

Code:
	int sortarray[100];
	int arrayin;
	int i = 0;
	
	while (fscanf(fp2, "%d", &arrayin) != EOF)
	{
		sortarray[i] = &arrayin;
		i++;
	}
I can't get the below to work from above? Not sure how to assign the numbers read in from the .txt file into the array. Maybe this isn't the correct way to do this?

warning: assignment makes integer from pointer without a cast


Code:
sortarray[i] = &arrayin;
__________________

Blizzie
Κατεψυγμένα Στερεά

Hold on to the calm before the storm comes



System: Aeon
CPU
Q6600 G0 | 3.6 GHz @ 1.36v | 1.2375 VID
Motherboard
Foxconn BlackOps X48 | Quantum Force
Memory
2x2 GB DDR3 OCZ Reapers HPC | 1.6 GHz 7-7-7-24
Graphics Card
EVGA GTX 260 Core 216 | 702/1404/1242
Hard Drive
500GB WD5000AAKS | 1TB WD1001FALS
Sound Card
Creative X-Fi XtremeGamer
Power Supply
Corsair CMPSU 550VX 550W
Case
Antec Nine Hundred
CPU cooling
Zalman CNPS9700
GPU cooling
Stock
OS
Windows 7 Professional x64
Monitor
Envision 22 in. LCD Widescreen | 1680x1050
Blizzie is offline Overclocked Account   Reply With Quote
Old 05-26-09   #10 (permalink)
Security Sleuth
 
Pooping^fish's Avatar
 
intel nvidia

Join Date: Jul 2007
Location: egypt
Posts: 1,266

Rep: 67 Pooping^fish is acknowledged by some
Unique Rep: 62
Trader Rating: 3
Default

Whyre you passing the address of arrayin? Thats of course where your warning(s) is.

You said you have a file containing the data, then in your example show a variable being used. Well, which is it?
Read from a file, seperating by newlines or however you so choose, store this data somewhere for manipulation.

The post of yours above spots about the ';', a quick look shows you left our a ')'.

Lastly, if you look above I posted an example of a recursive fib function. Use the idea as needed.
__________________
Quote:
"O, hai! Want som pRon? Dwnlod ths kodk frst. Its teh bst pRonz ever, we prmis." -GibbyGano
Proud Member of the Linux Gaming Community
I am your friend.

System: ragequit
CPU
Q9550 4ghz @ 1.25v
Motherboard
Asus Max 2 formula
Memory
OCZ LV blade 1:1 950mhz
Graphics Card
8800gtx 610/1ghz
Hard Drive
7200.10 250gb
Sound Card
X-FI Extreme Music
Power Supply
750w Toughpower
Case
Lian li pc-65
CPU cooling
TRUE
GPU cooling
stock
OS
leetlinucks
Monitor
24" Westy
Pooping^fish is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -5. The time now is 11:10 PM.


Overclock.net is a Carbon Neutral Site Creative Commons License

Terms of Service / Forum Rules | Privacy Policy | DMCA Info | Advertising | Become an Official Vendor
Copyright © 2009 Shogun Interactive Development. Most rights reserved.
Page generated in 0.17619 seconds with 8 queries