gerard4143 371 Nearly a Posting Maven

You would probably have better luck with something else...Try getting the MAC address of the network card, that's supposed to be unique.

gerard4143 371 Nearly a Posting Maven

I would look into the modulus operator using it something like below.

using System;

namespace testit
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			UInt64 x = 0;
			
			Console.Write("Enter a four digit number->");
			x = UInt64.Parse(Console.ReadLine());
			Console.WriteLine(reverse_it(x));
		}
		
		public static UInt64 reverse_it(UInt64 num)
		{
			UInt64 reverse = 0;
			
			byte [] ans = new byte[]{0,0,0,0};
			
			ans[3] = (byte)(num % 10);
			num = (num -= num % 10) / 10;
			ans[2] = (byte)(num % 10);
			num = (num -= num % 10) / 10;
			ans[1] = (byte)(num % 10);
			num = (num -= num % 10) / 10;
			ans[0] = (byte)(num % 10);
			num = (num -= num % 10) / 10;
			
			for (UInt64 i = 3; i > 0; --i)
			{
				reverse += ans[i];
				reverse *= 10;
			}
			reverse += ans[0];
			return reverse;
			
		}
	}
}
gerard4143 371 Nearly a Posting Maven

On line 57...Try initializing your double variables to 0.0

gerard4143 371 Nearly a Posting Maven

hi,
Is it possible pass the value without using pthread_create() function?...
ie , directly pass the value to that thread function...

You must understand that a pthread shares the address space with the main executable so it literally has access to anything that the main executable has access to.

gerard4143 371 Nearly a Posting Maven

Yes its possible, that's why it has the void* args parameter.

gerard4143 371 Nearly a Posting Maven

I am currently reading up on MySQL C API . Like shown, i have my client written in c++ but the API is written in C. Is it possible to put the C code within my c++ client? I am using Xcode on my MAC.

Im new to all of this so please don't be hard on me.

Yes, you can use the C api in a C++ application.

gerard4143 371 Nearly a Posting Maven

Connecting to a MySql database manually is not the way to go...Download the MySql developer files and use that library(MySql's).

Note the enclosed code

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <mysql.h>//Note the mysql header file

#define SEL_QUERY "select * from personal where lastname = '"
#define SQUOTE "'"
#define FIELD_SIZE 35

int main(int argc, char**argv)
{
	MYSQL *conn;
	MYSQL_RES *res;
	MYSQL_ROW row;

	bool foundit = false;

	char user[] = "root";
	char password[] = "";
	char database[] = "gerarddb";
	char server[] = "localhost";
	
	char query[strlen(SEL_QUERY) + strlen(SQUOTE) + FIELD_SIZE];
	query[0] = '\0';

	strcat(query, SEL_QUERY);
	strcat(query, argv[1]);
	strcat(query, SQUOTE);

	conn = mysql_init(NULL);

	if (!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0))
	{
		fputs(mysql_error(conn), stderr);
		exit(EXIT_FAILURE);
	}

	if (mysql_query(conn, query))
	{
		fputs(mysql_error(conn), stderr);
		exit(EXIT_FAILURE);
	}

	res = mysql_use_result(conn);

	while ((row = mysql_fetch_row(res)) != NULL)
	{
		foundit = true;
		fprintf(stdout, "%s,%s,%s,%s,%s,%s\n",row[0],row[1],row[2],row[3],row[4],row[5]);
	}

	if ( !foundit )
	{
		fprintf(stderr, "'%s' produced an empty dataset!\n", argv[1]);
	}

	mysql_free_result(res);
	mysql_close(conn);
	exit(EXIT_SUCCESS);
}
gerard4143 371 Nearly a Posting Maven

Your function prototype is incorrect..You have

int giveMemoryBack (CDROM int *pCDROM1, int *pCDROM2, int *pCDROM3)

and it should be

int giveMemoryBack (CDROM *pCD1, CDROM *pCD2, CDROM *pCD3)
{
delete pCD1;
delete pCD2;
delete pCD3;
return 0;
}

and calling your function should be

// Call giveMemoryBack function
giveMemoryBack(pCDROM1, pCDROM2, pCDROM3);
gerard4143 371 Nearly a Posting Maven

Look at your inner condition

while (payrollAmount >= 0)

To exit this loop you must set payrollAmount < 0. What happens the next time around? payrollAmount is still set to < 0. You have to set payrollAmount back to zero when you exit the inner loop.

gerard4143 371 Nearly a Posting Maven

Shouldn't you do your totalPayroll += payrollAmount in the inner loop? As it is, your inner loop just prompts for and accepts a value for payrollAmount.

gerard4143 371 Nearly a Posting Maven

I tried something in your code and it seems to work. I essentially knocked the x value back by one if an exception is thrown...

sing System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Exceptional
{
    class WorkerTest
    {
        static void Main(string[] args)
        {
            Worker[] workerArray = new Worker[2];

            int workerID;
            double hrSal;
			
            for (int x = 0; x < workerArray.Length; x++)
            {
                try
                {
			loadId(x, out workerID);
			loadSal(x, out hrSal);

                    workerArray[x] = new Worker(workerID, hrSal);//only reach here if no exceptions thrown
                }

                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
			--x;//knock counter back by one and start again.
                }

            }
            Console.WriteLine();
            for (int i = 0; i < workerArray.Length; i++)
            {
                Console.WriteLine("Worker # {0} \nHourly salary {1}\n--------\n ", workerArray[i].workerID, workerArray[i].hrSal.ToString("C"));
            }
        }
		private static void loadSal(int position, out double val)
		{
			Console.Write("Input an hourly Salary for the worker[{0}]: ", position);
            val = Convert.ToDouble(Console.ReadLine());
			
			if (val < 5.0 || val > 55.0)
			{
				throw new ArgumentException("Unexpected Salary Range.");
			}
		}
		
		private static void loadId(int position, out int val)
		{
			Console.Write("Input a work identification number for worker[{0}]: ", position);
            val = Convert.ToInt32(Console.ReadLine());
		}
    }

    class Worker
    {
        public int workerID;
        public double hrSal;

        public Worker(int WorkerID, double HrSal)
        {
            workerID = WorkerID;
            hrSal = HrSal;
        }
    }
}
gerard4143 371 Nearly a Posting Maven

Ideally you would use the std::vector class instead of trying to manage dynamic memory and pointers.

Yeah, the standards committee spent all that time creating the standard temple libraries maybe we should consider the vector.

gerard4143 371 Nearly a Posting Maven

No no no.. You've mis understood me. So lets say the string is "The man ate all of the ham yesterday before we came home." I want the output to be:

e found
e found
etc....
and
o found
o found
etc...

Your example doesn't make sense. What are you looking for?

gerard4143 371 Nearly a Posting Maven

I thought CDROM was an object not integer? You should use

int deleteCD(CDROM *one, CDROM *two) { 
delete one;
delete two;
return 0;

Ooops missed that.

gerard4143 371 Nearly a Posting Maven

Your giveMemoryBack function should be

int giveMemoryBack (int *pCDROM, int *pCDROM2, int *pCDROM3)
{
delete pCDROM1
delete pCDROM2
delete pCDROM3
return 0;
}

Note: Remember to set the original pointers back to NULL.

Found something else, your function call

// Call giveMemoryBack function
int giveMemoryBack(int *pCDROM1, int *pCDROM2, int *pCDROM3);

is incorrect. It should be.

// Call giveMemoryBack function
giveMemoryBack(pCDROM1, pCDROM2, pCDROM3);
gerard4143 371 Nearly a Posting Maven

If you examine the strchr prototype you'll note it doesn't take a c-string for the second parameter.

char *strchr(const char *s, int c);

You'll have to do more than one search if you use this function.

gerard4143 371 Nearly a Posting Maven

You could create a dynamic array with the operator new.

int * a = new int[size];
gerard4143 371 Nearly a Posting Maven

Ok, that makes sense! I didn't think of implicit destructors cleaning up my object - again, still learning this stuff!

Thanks for the clarification. Now, I just need to figure out how to reassign the values instead of cleaning them up when the exception is thrown!

Usually you handle range and out of range situations without exceptions. You should be able to check for input validity before the constructor is called.

gerard4143 371 Nearly a Posting Maven

Thanks for your responses! The explanation that Momerath gave me an idea of why I'm getting the NullReferenceException - now I just need to figure out how to rewrite it so that my default values in Worker are used when the exception is called, rather than just setting those values to null. I'll post with an update as its available.

Gerard - I don't know too much about destructors other than using them for cleanup. Could they still be applicable if I want to reassign variables to a default value?

Just a side note* - Please forgive my ignorance as I'm still relatively new to the C# programming language. Again, thank you for your help! I'll get cracking at this again and update you all on the solution (HOPEFULLY without more questions, though additional aid is always appreciated! :-))

I think one of your problems stem from the constructor throwing an exception when one of your parameters is one of range. When the constructor throws an exception the destructor is called cleaning up the object.i.e. The object doesn't exist.

gerard4143 371 Nearly a Posting Maven

Here's a little code snippet that may help you understand what's happening..Code from here - http://stackoverflow.com/questions/188693/is-the-destructor-called-if-the-constructor-throws-an-exception

using System;

class Test
{
    Test()
    {
        throw new Exception();
    }

    ~Test()
    {
        Console.WriteLine("Finalized");
    }

    static void Main()
    {
        try
        {
            new Test();
        }
        catch {}
        GC.Collect();
        GC.WaitForPendingFinalizers();
    }
}
gerard4143 371 Nearly a Posting Maven

O.K. I'll try it again.

gerard4143 371 Nearly a Posting Maven

So going from a meager understanding of scanf to posix threads.

gerard4143 371 Nearly a Posting Maven

I just copied and ran your program and it worked.

gerard4143 371 Nearly a Posting Maven

put this '%i' instead of "%d" ??

No, just take the address of the structure member.

scanf("%d",&std.age);//now your passing an int*
gerard4143 371 Nearly a Posting Maven

A question off-topic

#include<iostream.h>

What examples/materials are you using that recommend iostream.h?

gerard4143 371 Nearly a Posting Maven

You have to start reading your error messages..

"warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘int’"

scanf("%d",std.age);//how do you make std.age an int pointer?
gerard4143 371 Nearly a Posting Maven

If your scanf'ing a variable, you must use the address of the variable...If the variable name is an address(like character arrays) then you don't have to use the address of operator on it.

example

char my_str[] = "This is my string";
int x = 1234;

scanf("%s", my_str);//my_str is an array so no &
scanf("%d", &x);
gerard4143 371 Nearly a Posting Maven

Put the & back for lines 25 and 37...I'm really getting the impression that your guessing about the implementation of scanf. I would try google scanf tutorial.

gerard4143 371 Nearly a Posting Maven

Try this

scanf("%s",stud1.oname);//remove the &
gerard4143 371 Nearly a Posting Maven

Line 97. What is this

if(s[i].sMaxCap <= h[0,1,2,3,4,5,6,7,8,9].maxCap)
gerard4143 371 Nearly a Posting Maven

I got a segfault in the strcpy function.

gerard4143 371 Nearly a Posting Maven

Line 15 should be...

scanf ("%d",&temp);
gerard4143 371 Nearly a Posting Maven

Try running your code with a debugger.

gerard4143 371 Nearly a Posting Maven

left node and right node where left node is greater that right node.

gerard4143 371 Nearly a Posting Maven

For Linux Kernel Modules I just use

obj-m += test.o

all:
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
gerard4143 371 Nearly a Posting Maven

A big hint is the function name - findnoise.

I think the function is grabbing whatever stack value int x happens to have and then applying some operations on it...Hopefully returning a quasi random number.

Please note this is just a guess....Actually I never noticed the function passed an int x. That kind of throws off my guess.

gerard4143 371 Nearly a Posting Maven

atoi() only works on c-strings, not on characters.

Actually if you think about this, it is a c-string for an Itel/AMD type integer.

int i = getchar();
thisNumber += atoi((char*)&i);

If the user types a number say 5 then i(the int i) will be 0x35,0x0,0x0,0x0. So if you take the address of i you'll have a c-string...Yeah I know its a terrible hack but I did mention it in the remarks.

gerard4143 371 Nearly a Posting Maven

You could try something like below

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

unsigned long int readNumbersByGetchar()
{
  unsigned long int thisNumber = 0, i = 0;	

  while ((i = getchar()) != '\n')  
  {
	if (isdigit(i))
	{
	  thisNumber *= 10;
	  thisNumber += atoi((char*)&i);/*This only works for Intel/AMD type integers*/
	}
  }              
  return thisNumber;              
}

int main(int argc, char**argv)
{
  fprintf(stdout, "ans->%lu\n", readNumbersByGetchar());
  return 0;
}

/*
 18 446 744 073 709 551 615 - 64 bit Max value
 */
gerard4143 371 Nearly a Posting Maven

Please show us what you have so far.

gerard4143 371 Nearly a Posting Maven

Maybe you should've of asked some questions in your class.

On a different note. The forum frowns on students posting homework questions and asking for solutions. Please post what you've accomplished so far and ask specific questions about specific problems.

gerard4143 371 Nearly a Posting Maven

First question. What are you trying to do here? Are you trying to create a Windows form with a progress bar? If you are, this simple example should work.

using System;
using System.Drawing;
using System.Windows.Forms;

class myform: Form
{
    ProgressBar my_bar;
    
    public myform()
    {
        my_bar = new ProgressBar();

        my_bar.Minimum = 1;
        my_bar.Maximum = 100;
        my_bar.Value = 1;
        my_bar.Step = 1;
        my_bar.Size = new Size(225, 30);
        
        this.Text = "Click on the Progress Bar";
        this.Size = new Size(250, 200);
        this.CenterToScreen();
        
        my_bar.Click += new EventHandler(ClickProgressHandler);

        this.Controls.Add(my_bar);
    }
    
    private void ClickProgressHandler(object obj, EventArgs args)
    {
        ((ProgressBar)obj).Value += 5;
    }
}

namespace testit
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            myform me = new myform();
            Application.Run(me);
        }
    }
}
gerard4143 371 Nearly a Posting Maven

In your for statement

for(i = 0; i < 10; i++) {
printf("value, deference pointer, address \n");
printf("pointer1 = %p, *pointer1 = %d, &pointer1 = %p\n", pointer1, *pointer1, &pointer1);
pointer1++;//this line should go last
}

Or better yet.

#include <stdio.h>

int main(void) 
{
	int values[10] = {1,2,3,4,5,6,7,8,9,10};
	int *pointer1;
	pointer1 = values;

	while ( pointer1 < &values[10] )
	{ 
	  fprintf(stdout, "address->%p, value->%d\n", (void*)pointer1, *pointer1);
	  ++pointer1;
	}

	return 0;
}
gerard4143 371 Nearly a Posting Maven

Because the data member is const the = operator can't change its value. So using the = operator on any objects from this class will cause an error.

Your = operator is defined ~ like so

A& A::operator =(const A & obj)
{
if (this != &obj)
{
a = obj.a;//fails here since a is const
}
return *this;
}
Jsplinter commented: Thank you. Clear explanation. +3
gerard4143 371 Nearly a Posting Maven

Becuz I don't know how to implement. Can u show me other way?

Not without thinking of some obscure, confusing and probably non-portable way...Maybe someone else can think of a simple way to handle this problem.

gerard4143 371 Nearly a Posting Maven

Erm is there other way to do rather than structures

Yes but why would you? A structure is made to host many different variables in one nice neat (pardon the word usage) structure.

gerard4143 371 Nearly a Posting Maven

Then you have to explicitly refer to the members

public void a.b()
{
// TODO: Add Class1.d implementation
}
gerard4143 371 Nearly a Posting Maven

You would be better served if you created an array of structures.

#include <stdio.h>
#include <stdlib.h>

struct mys
{
  int id, size, PerBox;
  double Price;
};

int main()
{
  struct mys thes[5];
  return 0;
}
gerard4143 371 Nearly a Posting Maven

thank you.. but since i am a beginner, i really need a good topic.. can you suggest me one, so that i can work on it and show it to you people before submitting it?

Create a dynamic array in C.

gerard4143 371 Nearly a Posting Maven

sorry.. i thought you would help .. i never post here again..

The forum rules stipulate that the posters must show some effort by posting what he/she has accomplished so far...If that's asking too much then adios amigo.

gerard4143 371 Nearly a Posting Maven

please help me.. contribute some codes for indegree and outdegree .. i need it badly

How about you contributing what you have so far.