gerard4143 371 Nearly a Posting Maven

I just ran your program and it worked...What are you using for data in your data01.dat file?

gerard4143 371 Nearly a Posting Maven

Try changing the code like

for(int i=0; i<records && inFile; i++)
		{
			for(int j=0; j<month; j++)
			{
				int ans = 0;
				inFile >> ans;
				
				if (!inFile) break;
			
				monthArray[i][j] = ans;
			}
		}
gerard4143 371 Nearly a Posting Maven

Try something like

for(int i=0; i<records && inFile; i++)
		{
			for(int j=0; j<month && inFile; j++)
			{
				inFile >> monthArray[i][j];
			}
		}
gerard4143 371 Nearly a Posting Maven

in C, the keyword const doesn't exist, but it does in C++.

#define is used often in C to declare a name for a value that doesn't ever change throughout the execution of the program. This makes it easier to change values that are used over and over again.

Please read this link

http://tigcc.ticalc.org/doc/keywords.html

gerard4143 371 Nearly a Posting Maven

Your missing a ) and have one too many ;

if (progressBar1->Value == 2000)
{
label1->Text = "Hello";
}
gerard4143 371 Nearly a Posting Maven

i understood my mistakes...thanks gerrard...although in your code...
when starting a new thread the value of t passed is always 2 and never 1...

where it should say Thread 1 started..it says Thread received 2 Thread received 2
instead of Thread received 1 Thread received 2

how is that ?

Your passing the address of t not its value, so when you change t to two its reflected in both threads.

gerard4143 371 Nearly a Posting Maven

Could you post the error and use the code tags?

gerard4143 371 Nearly a Posting Maven

I cleaned your code up a little...well a lot

#include<pthread.h>
#include<stdio.h>
#include<sys/types.h>
#include<semaphore.h>
#include<unistd.h>

pthread_t t1,t2;
pthread_attr_t tattr;
int counter;
sem_t mutex;

void* runner(void *arg)
{
	int i = 0;

	printf("Thread received %i\n", *(int*)arg);

	for(i = 0; i < 5; i++)
	{
		sem_wait(&mutex);
		printf("Thread %i says %i\n",*((int *)arg),counter);
		counter++;
		sem_post(&mutex);
		sleep(1);
	}
	return (void*)NULL;
}

int main()
{
	int r;
	int t = 1;

	printf("hi");
	r = sem_init(&mutex,0,1);
	r = pthread_attr_init(&tattr);

	r = pthread_create(&t1,&tattr,runner,(void *)&t);

	t = 2;

	r = pthread_create(&t2,&tattr,runner,(void *)&t);

	printf("Threads initialised");
	r = pthread_join(t1,NULL);
	r = pthread_join(t2,NULL);
	r = sem_destroy(&mutex);

	return 0;
}

P.S.

This is a pet peeve of mine

r=sem_destroy(&mutex);

It makes the code impossible to read, please consider a more readable format like below.

r = sem_destroy(&mutex);

compile line:
gcc test.c -Wall -ansi -pedantic -o test -pthread

gerard4143 371 Nearly a Posting Maven

Your kidding right? What is this this? Spam?

gerard4143 371 Nearly a Posting Maven

Well the member function 'get_gas' requires a double..

void Car::get_gas(double fuel_level)
gerard4143 371 Nearly a Posting Maven

I have a constant value that is inside of the brackets (just forgot to type it in the example) if that is what you are talking about, otherwise please enlighten me.

Maybe you can enlighten me as to how we(Daniweb) can diagnose a problem if the code is not complete.

gerard4143 371 Nearly a Posting Maven

You realize this is wrong

char* array [];

This is taken from your original posting.

gerard4143 371 Nearly a Posting Maven

Why are you doing it this way? Try sorting the values and then print them.

gerard4143 371 Nearly a Posting Maven

The library name is stdio.h not studio.h

gerard4143 371 Nearly a Posting Maven

Try something like below

#include <stdio.h>
#include <string.h>

char data[] = "Hello, World!";
const char *delimiters = " ";  

void function (char* array [])
{
	array[0] = strtok (data, delimiters);

	fprintf(stdout, "first string->%s\n", array[0]);

	array[1] = strtok(NULL, delimiters);

	fprintf(stdout, "second string->%s\n", array[1]);
}

int main () 
{
	char* array[2];
	function(array);

	fprintf(stdout, "first string->%s\n", array[0]);

	fprintf(stdout, "second string->%s\n", array[1]);

	return 0;
}
gerard4143 371 Nearly a Posting Maven

Well to print a row you would hold the row index constant and then vary the column from 0 - max_column...So to print a column you would hold a column constant and vary the row from 0 - row_max.

For row 2, i varies from 0 - max_column

my_arr[2]

for column 3, i varies from 0 - max_row

my_arr[3];

gerard4143 371 Nearly a Posting Maven

Its called forward declaration and its used so the compiler has an idea what player1 is.

int player1(void);

This is all the information the compiler needs to generate a function call to player1.

gerard4143 371 Nearly a Posting Maven

Put this line before the function player2

int player1(void);
gerard4143 371 Nearly a Posting Maven

You really should use a library like XDR(external data representation) to pass data across a network. It'll ensure that the network byte order is maintained.

gerard4143 371 Nearly a Posting Maven

you had an error in your structure declaration and a questionable variable.

#include<stdio.h>

#include<stdio.h>
typedef struct contact
{
        char name[1][20];/*why do you have this*/
        struct number
        {
                double num;
        }no;
} myc;

int main()
{
	myc thec;
	thec.no.num = 1234;

	fprintf(stdout, "num->%f\n", thec.no.num);
	
	return 0;
}
gerard4143 371 Nearly a Posting Maven
#include<stdio.h>
int main()
{
        int i,j,pass;
        char p[3][10],temp[1][10];
        temp[0]='\0';
        printf("please enter 3 words\n");
        for(i=0;i<3;i++)
        {
                scanf("%s",&p[i]);

        }

        for(pass=0;pass<3;pass++)
        {
                for(i=0;i<3;i++)
                {
                        j=0;

                        repeat:if(p[i][j]<p[i+1][j])
                               continue;
                               else if(p[i][j]>p[i+1][j])
                               {
                                        temp[0]=p[i];
                                        p[i]=p[i+1];
                                        p[i+1]=temp[0];
                               }
                               else
                               {
                                        j++;
                                        goto repeat;
                               }
                }
        }
        for(i=0;i<3;i++)
        {
                printf("%s\n",p[i]);
        }
        return 0;
}

I'm pretty sure that your line 10

scanf("%s",&p[i]);

Is just as dangerous gets().

Try running this program

#include<stdio.h>

int main()
{
	char b[] = "test this";
	char a[10];
	

	fputs("enter a long word like Pseudopseudohypoparathyroidism->", stdout);
	scanf("%s", a);

	fprintf(stdout, "a->%s\n", a);
	fprintf(stdout, "b->%s\n", b);	
	return 0;
}

The output on my machine was

a->Pseudopseudohypoparathyroidism
b->parathyroidism

which indicates a buffer overflow.

Mouche commented: Good example of buffer overflow +5
gerard4143 371 Nearly a Posting Maven

Are constants, defined by using the keyword const , external linkage or internal linkage?
Can constants be modified using pointers?
What about constants defined using by #define?

Can constants be modified? It really depends on what you mean by modified. Does that imply the use of memory management functions?

gerard4143 371 Nearly a Posting Maven

Try this

MessageBox(NULL, L"Text", "Title", MB_OK | MB_ICONEXCLAMATION);
gerard4143 371 Nearly a Posting Maven

Try this for Main line 13.

testHand[0].addCard(testDeck.dealCard());
gerard4143 371 Nearly a Posting Maven

First, you'll have to create a < operator for your class and then you'll have to create a function that compares two objects of that class using the < operator and then call the sort algorithm

sort(your_vector.begin(), your_vector.end(), sort_function);

Here's a simple example

#include <iostream>
#include <vector>
#include <algorithm>

class myint
{

public:

    myint(int val):itsvalue(val) {}

    bool operator <(const myint & m) const { return itsvalue < m.itsvalue; }

    int getitsvalue() const { return itsvalue; }

private:

    int itsvalue;

};

bool myint_compare(const myint & a, const myint & b)
{
    return a < b;
}

std::ostream& operator <<(std::ostream & out, const myint & m)
{
    return out << m.getitsvalue();
}

int main()
{
    std::vector<myint> the_ints;

    for (int i = 8; i > 0; --i)
        the_ints.push_back(i);

   for (int i = 0; i < 8; ++i)
           std::cout << the_ints[i] << std::endl;

   sort(the_ints.begin(), the_ints.end(), myint_compare);

   std::endl(std::cout);

   for (int i = 0; i < 8; ++i)
           std::cout << the_ints[i] << std::endl;

    return 0;
}
gerard4143 371 Nearly a Posting Maven

Before you concern yourself with averages I would get your while loop working, as it is you read the last grade twice.

Try changing your loop condition to something like...

while( fscanf(infile, "%d", &numA) != EOF)
gerard4143 371 Nearly a Posting Maven

Try QT Creator, its a multi platform IDE(Windows, Mac, Linux, Unix).

gerard4143 371 Nearly a Posting Maven

No, technically it is a C-string. It has quotes which by definition ends in a NULL value. The definition actually overflows the array.

Thank-you WaltP

I appreciate your technical prowess with these questions..and I hope you realize this is sincere...

gerard4143 371 Nearly a Posting Maven

I see a problem right away

char list[9][31];
char sorted[9][31];
//--------Main Program Body----------
cout << "****Alphebetical Sorting Program***"<<endl<<endl;
cout<<"please enter 10 strings you wish to sort"<<endl;

Your arrays are 9 X 31 and should be 10 X 31.

beejay321 commented: wrong comment, i did that and it messed it up, i did what i had originally and it was fine +0
gerard4143 371 Nearly a Posting Maven

What is this this? Spam.

gerard4143 371 Nearly a Posting Maven

Could you please clean up your posted code. Its almost impossible to read.

Your problem, by the way

void getDerivative() (double [],int[]);

should be

void getDerivative(double [],int[]);
gerard4143 371 Nearly a Posting Maven

Like so

char my_ch = string[2];
gerard4143 371 Nearly a Posting Maven

Firstly, on line 68

newloc=malloc(sizeof(struct bstree *));

your allocating memory for the size of a pointer not the size of struct bstree..It should be

newloc=malloc(sizeof(struct bstree));
gerard4143 371 Nearly a Posting Maven

Try adding this

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
	double root1,	root2, a, b, c,	root;

	cout << "Enter the coefficients a, b, c: ";
	cin  >> a >> b >> c;

	root = sqrt (b*b - 4.0*a*c);
	root1 =	.5*(root - b) / a;
	root2 =	-.5*(root - b) / a;
	cout << "The solutions are: " << root1  << " and " << root2 << "\n";

	cin >> b;

	return(0);
}
gerard4143 371 Nearly a Posting Maven

I fail to see how this won't work

#include <stdio.h>
#include <stdbool.h>
#include <ctype.h>
#include <string.h>

bool isValidNum( char *str )
{
	int i = 0;
	
	for (i = 0; i < strlen(str) - 1; ++i)
	{
		if (!isdigit(str[i]))
			return false;
	}

	return true;
}

int main()
{
	char string[10];

	fputs("enter a number->", stdout);
	fgets(string, 10, stdin);

	printf("%d", isValidNum(string));

	return 0;
}
gerard4143 371 Nearly a Posting Maven

the main reason im not doing it like this is because the idnum must be atleast 5 digits long! your way is nice :) but wont quite work for my situation

I really don't understand your concerns. If you have more information, please post it.

gerard4143 371 Nearly a Posting Maven

I would try simplifying your code...

#include <stdio.h>
#include <stdbool.h>
#include <ctype.h>
#include <string.h>

bool isValidNum( char str[] )
{
	int i = 0;
	
	for (i = 0; i < strlen(str); ++i)
	{
		if (!isdigit(str[i]))
			return false;
	}

	return true;
}

int main()
{
	char string[] = {'\0','\0','\0','\0','\0'};

	printf("%d", isValidNum(string));

	return 0;
}
gerard4143 371 Nearly a Posting Maven

ravenous beat me to the answer.

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

int main(int argc, const char **argv)
{
	char ch[] = "12";

	int ans = atoi(ch);

	fprintf(stdout, "ans->%d\n", ans);
	return 0;
}
gerard4143 371 Nearly a Posting Maven

Ok got it now. But why do i need to wrap another pointer around it?

If you think about what happens when you call a function, it makes sense.

When you call your function the first thing it does is create temporary variables for the function arguments then it copies the values into to it...

So if we have a function like so

void myfunc(int * i);

and have a int pointer like so

int *iptr = NULL;

When we call myfunc(iptr) we'll create a temporary variable for the parameter i and copy the contents of iptr into it. Notice we copied NULL into the temporary and iptr still equals NULL.

Now lets look at my scenario where I define my function like so

void myfunc(int **i);

and we'll use the same pointer

int *iptr = NULL;

Now when I call the function I pass the address of iptr which is copied into the temporary(myfunc(&iptr)) so we can access the original pointer value with simple dereferencing.

gerard4143 371 Nearly a Posting Maven

Right from my help files.

int atoi(const char *nptr);

The atoi() function converts the initial portion of the string pointed
to by nptr to int.

atoi accepts a c-string not a char.

gerard4143 371 Nearly a Posting Maven

What is 'some_char'?

gerard4143 371 Nearly a Posting Maven

This doesnt even compile-.-

That's odd, it compiles on my system without a warning or error. It also runs correctly.

I'm using

gcc (GCC) 4.4.3

gerard4143 371 Nearly a Posting Maven

Yes to all your questions. C is a general purpose programming language.

gerard4143 371 Nearly a Posting Maven

Try doing it like below

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

typedef struct mystruct
{
    int a;
}mytype;

mytype* createMytype(int x)
{
    mytype *mt;

    mt = (mytype*)calloc(1, sizeof(mytype));

    mt->a = x;

    return mt;
}

int foo(mytype** mt)
{
    *mt = createMytype(6);
    return 0;
}

int bar(mytype** mt)
{
    printf("%d\n", (*mt)->a);
    return 0;
}

int main(int argc, const char **argv)
{
    mytype *mt = NULL;

    foo(&mt);
    bar(&mt);
    exit(0);
}
gerard4143 371 Nearly a Posting Maven

I tried this and got 1311780402.

#include <stdio.h>

union myu
{
	unsigned int x;
	char ch[4];
};

int main()
{
	union myu the_u;

	the_u.ch[0] = 50;
	the_u.ch[1] = 46;
	the_u.ch[2] = 48;
	the_u.ch[3] = 78;

	fprintf(stdout, "x->%u\n", the_u.x);

	return 0;
}
gerard4143 371 Nearly a Posting Maven

Try something like this

#include<stdio.h>

int main()
{
	int i = 0;
	char p[10][10];
	printf("please enter 10 words\n");

	for(i = 0; i < 10; i++)
	{		
		fgets(&p[i][0], 10, stdin);
		printf("\n");
	}

	for(i = 0; i < 10; i++)
	{
		printf("%s", &p[i][0]);
		printf("\n");
	}

	return 0;
}

A few pointers..Please use code tags and never use gets() its a dangerous function.

gerard4143 371 Nearly a Posting Maven

You have to understand, we can't even imagine why you have conditions like so

while(!( (scanRet != EOF && scanRet != 0) && (ptr[i].ssContrib >= 0 && ptr[i].ssContrib <= 8000) ) );

You have comments explaining why your including this library or that one but no comments as to why you have these gargantuan conditionals...If you look at most code. you'll find that simplicity rules.

gerard4143 371 Nearly a Posting Maven

Well first things first...This is C++ and not C, just look at your for statements and your includes.

gerard4143 371 Nearly a Posting Maven

Try something like below

#include<stdio.h>
int main ()
{
  
  int id = 0;

  float value1 = 0;
  float value2 = 0;
 
  
	while(id<=3)
	{
	 	printf("Please enter the id number - 1 to 2 - to end\n");
	      	scanf("%d",&id);
	  switch(id)
	  {
	  case 1:
	    value1 = 10 * 10;
	    printf("Value1 is: %f\n",value1);
	    break;
	    
	  case 2:
	    value2 = 20 * 20;
	    printf("Value2 is: %f\n",value2);
	    break;
	  
	  default:
	    printf("Wrong input\n");
	    break;
	  }
	}
		
      return 0;
}
gerard4143 371 Nearly a Posting Maven

Here's a cleaner version that uses the proper way to jump back.

#include <stdio.h>

#define SIZE 10
int test[SIZE];

int main()
{
	int i = 0;

	for (i = 0; i < SIZE; ++i)
		test[i] = i + 3;

	for (i = 0; i < SIZE; ++i)
		fprintf(stdout, "ans->%d\n", test[i]);

	__asm__
	(
		"pushq	%rdi\n\t"

		"xorq	%rdi, %rdi\n\t"		

		"1:\n\t"
		
		"cmpq	$9, %rdi\n\t"
		"je	2f\n\t"

		"movq	$0, test(, %rdi, 4)\n\t"

		"incq	%rdi\n\t"
		"jmp	1b\n\t"

		"2:\n\t"

		"popq	%rdi\n\t"
	);

	for (i = 0; i < SIZE; ++i)
		fprintf(stdout, "ans->%d\n", test[i]);
	return 0;
}