gerard4143 371 Nearly a Posting Maven

No your data is safe. When you reassign pointer, its just gets the address of your string "weeeeeeeeeeeeeeeeeeeeeee".

"hi" - has one address value.
"weeeeeeeeeeeeeeeeeeeeeee" - is another address value.

gerard4143 371 Nearly a Posting Maven

Try changing your array to..

int test[2][2][2];

Try running this code below

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

int test[1][1][1];
int test2[2][2][2];

int main()
{
	fprintf(stdout, "array elements->%lu\n", sizeof(test)/sizeof(int));
	fprintf(stdout, "array elements->%lu\n", sizeof(test2)/sizeof(int));
	return 0;
}
gerard4143 371 Nearly a Posting Maven

You should be able to call the destructor which should call delete of the variable that points to the next node.

gerard4143 371 Nearly a Posting Maven

Line 7

int area = (p(p - a)(p - b)(p - c))/2;

should probably be

int area = (p * (p - a) * (p - b) * (p - c))/2;

also line 13 your calling

convert();

You haven't defined a function convert.

gerard4143 371 Nearly a Posting Maven

I think it's Ctrl-D on those systems, actually.

Ooops my bad.

gerard4143 371 Nearly a Posting Maven

Ctrl+z

gerard4143 371 Nearly a Posting Maven

Because that's what the function does..Here's a quote from my help file

"int putchar(int c);
writes the character c, cast to an unsigned char, to stream"

gerard4143 371 Nearly a Posting Maven

When you enter a character from the console you hit return as well so you really enter two characters..e.g

Enter the character 'a' plus return yeilds

'a', '\n'

Instead of using putchar() try using

fprintf(stdout, "value->%d\n", t);
fprintf(stdout, "value->%d\n", x);

What values were displayed?

gerard4143 371 Nearly a Posting Maven

Well what's it supposed to do? Can you give us an example of how its failing?

Oh by the way, don't use fflush(stdin) its behavior is undefined.

gerard4143 371 Nearly a Posting Maven

In the simplest terms...Don't do this, its wrong.

ch1= (char *)realloc(ch1,1);
ch1++;

gerard4143 371 Nearly a Posting Maven

I don't like that your realloc'ing ch1 and then incrementing the pointer ch1. To me this seems like a recipe for disaster

gerard4143 371 Nearly a Posting Maven

Why? Because the posted code is full of errors.

gerard4143 371 Nearly a Posting Maven

Its very common to reassign pointers... So your line 14 is valid.

gerard4143 371 Nearly a Posting Maven

Try looking at the attached code...It may help straighten things out or it just might confuse you more..

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

int main()
{
	int i = 0;
	int *iptr = (int*)malloc(sizeof(int) * 10);
	int **tptr;

	for (i = 0; i < 10; ++i)
		*(iptr + i) = i;

	for (i = 0; i < 10; ++i)
		fprintf(stdout, "ans->%d\n", *(iptr + i));

	tptr = &iptr;

	for (i = 0; i < 10; ++i)
		fprintf(stdout, "ans->%d\n", *(*tptr + i));
	
	return 0;
}

I really should have used C++, so here look at this one

#include <iostream>

int main()
{
	int i = 0;
	int *iptr = new int[10];
	int **tptr;

	for (i = 0; i < 10; ++i)
		*(iptr + i) = i;

	for (i = 0; i < 10; ++i)
		std::cout << "ans->" << *(iptr + i) << std::endl;

	tptr = &iptr;

	for (i = 0; i < 10; ++i)
		std::cout << "ans->" << *(*tptr + i) << std::endl;
	
	delete [] iptr;
	
	return 0;
}
gerard4143 371 Nearly a Posting Maven

Its the same for both examples.

gerard4143 371 Nearly a Posting Maven

The memory manager is choking on your pointer 'p' because you incremented its value.

Check the enclosed code..

#include<iostream>
using namespace std;

int main()
{
  int* p=new int[2];
  p[0]=1;
  p[1]=2;
  cout<<p[0]<<" "<<&p[0]<<endl;
  cout<<p[1]<<" "<<&p[1]<<endl;
  cout<<endl;
  cout<<*p<<" "<<p<<endl;
  p++;
  cout<<*p<<" "<<p<<endl;
  p--;//set pointer back to its original value
  delete [] p;
}
gerard4143 371 Nearly a Posting Maven

If your going to increment your pointer then save its original value somewhere and delete that.

gerard4143 371 Nearly a Posting Maven

Line 19...Why are you closing write here?

actually line 16...Why are you opening write here?

Try looking at the code below

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

#define BSIZE 24

int main()
{
	char ch[BSIZE];
	FILE *fout;
	FILE *fin;

	if (!(fin = fopen("testfile", "r")))
	{
		fputs("could not open testfile!\n", stderr);
		exit(EXIT_FAILURE);
	}

	if (!(fout = fopen("testout", "w")))
	{
		fputs("could not open testout!\n", stderr);
		exit(EXIT_FAILURE);
	}

	while (fwrite(ch, sizeof(char), fread(ch, sizeof(char), BSIZE, fin), fout))
	{
	}

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

This code has some things that you should avoid like

fflush(stdin);

This is a no no.

Plus this

PATIENT_DATA section_1[40]= {"","","","",0,"","","","",0};

I'm not sure what the effect is here...Does it initialize the first element? I'm not really sure, one of the C language lawyers will have to comment on this one..

Here's a cleaned up version of the posted code

#include <stdio.h>

typedef struct
{
	char first_name[20];
	char middle_name[20];
	char last_name[20];
	char illness_type[5];
	int patient_number;
	char doctor_fname[20];
	char doctor_lname[20];
	char emer_fname[20];
	char emer_lname[20];
	int emer_telephone;
} PATIENT_DATA;

int main()
{ 

	PATIENT_DATA section_1 = {"","","","",0,"","","","",0};
	printf("\nPatient First Name: ");

	fgets(section_1.first_name, sizeof(section_1.first_name), stdin);

	return 0;
}

Please note, if you post code use the code tags.

gerard4143 371 Nearly a Posting Maven

Hi guys,thanks for the remedies.However on using fgets the compiler generated two errors of the same nature.It was like 'too few arguements passed to function 'fgets''.I am trying to read more about fgets and I will see what i'll come up with.For now thanks!

Take this in the way its intended...or not. Did you actually google how to use fgets()?

gerard4143 371 Nearly a Posting Maven

Your created an array of structures

struct secguard guard_rec[300];

So to access one element of your array you must use an array index like

gets(guard_rec[0].first_name);

Oh by the way the use of gets is really frowned upon...really. Here's why

BUGS
Never use gets(). Because it is impossible to tell without knowing the
data in advance how many characters gets() will read, and because
gets() will continue to store characters past the end of the buffer, it
is extremely dangerous to use. It has been used to break computer
security. Use fgets() instead.

Ooops Narue got here first

gerard4143 371 Nearly a Posting Maven

@kamatari..not yet..!!!
bt i am thinking of making a game and it will surely take time.
our teachers has informed us about dis project at the last moment.

If the teachers dumped this project on the class 'at the last moment' then I expect the class and yourself will have to 'do the best you can'.

jonsca commented: Well put. +6
gerard4143 371 Nearly a Posting Maven

Your example on line 3

someFN( &classInstance );

This passes the address of classInstance not the reference of classInstance.

gerard4143 371 Nearly a Posting Maven

Try changing line 29 to

myQ.AddMSG(myNewMessage);

gerard4143 371 Nearly a Posting Maven

Try this

g++ testit.cpp -E testit >testfile

gerard4143 371 Nearly a Posting Maven

Is there a toUpper or toLower in C/++ ?

The ctype.h library has functions

int toupper(int c);
int tolower(int c);

gerard4143 371 Nearly a Posting Maven

I would look at two for loops

for (int i  0; i < x; ++i)
{
	for (int j = 0; j < y; ++j)
	{

	}
}
gerard4143 371 Nearly a Posting Maven

Here's the output from my computer

Parent Writing [0]...
Parent Writing [1]...
hello there
Parent Writing [2]...
Parent Writing [3]...
Parent Writing [4]...
Parent Writing [5]...
Parent Writing [6]...
Parent Writing [7]...
Parent Writing [8]...
Parent Writing [9]...
[gerard@localhost test]$ hello there
hello there
hello there
hello there
hello there
hello there
hello there
hello there
hello there

[g@localhost]$

Just hit the enter key when the program is over.

gerard4143 371 Nearly a Posting Maven

An array define like so

int my_array[4];

has elements 0 - 3 not 0 - 4

gerard4143 371 Nearly a Posting Maven

You missed the point. Your function is expected to return an integer

int init_socket(int *sockfd);

But the logic in the body of the function doesn't return anything when socket creation is successful.

If you had this situation below where the socket creation was successful

int ans = init_socket(&sock);

What would the value of ans be?

gerard4143 371 Nearly a Posting Maven

Erase will call the string's destructor hence destroying the string object.

gerard4143 371 Nearly a Posting Maven

I'm not sure what your trying to accomplish here...Are you try to create a unique socket API for both Windows and Linux?

Oh by the way, your Linux function is lacking..What does it return if its successful?

gerard4143 371 Nearly a Posting Maven

Yes that's correct if your input buffer is empty.

vedro-compota commented: ++++++ +1
gerard4143 371 Nearly a Posting Maven

This might be your problem...

On line 14 your freeing Curr and then on line 16 you set Prev to Curr...Prev now equals NULL.

gerard4143 371 Nearly a Posting Maven

Are these supposed to be floats?

float Place_Of_Birth;
float Email_Address;

It makes more sense to have it as

char Place_Of_Birth[45];
char Email_Address[45];

Your scanf is incorrect here

scanf ("%c",&Name);

You need to scan for a c-string

scanf ("%s",Name);

These lines are wrong..

scanf ("%s",&Place_Of_Birth);
scanf ("%s",&Email_Address);

should be

scanf ("%s",Place_Of_Birth);
scanf ("%s",Email_Address);

Ooops missed one.

char Name;

should be

char Name[45];

Your making some fundamental errors in your code, I would track down a good intro into the subject of C programming.

gerard4143 371 Nearly a Posting Maven
moroccanplaya commented: thanks +1
gerard4143 371 Nearly a Posting Maven

You should use strcmp here not ==

if(input[0] == "ls")

it should be

if (!strcmp(input, "ls"))

gerard4143 371 Nearly a Posting Maven

Yeah you might want keep input as a c-string and use strcmp for your comparisons.

gerard4143 371 Nearly a Posting Maven

Try writing your code like this...please note that I write to the file and then close and then open for input.

#include <iostream>
#include <fstream>
#include <cstdlib>

using namespace std;

int main()
{
	ofstream		file1("test");

	int random = rand() % 100;
	cout << random << endl;
	file1.write((char *)&random, sizeof(int));

	file1.close();

	ifstream		file2("test");

	int read;
	file2.read((char *)&read, sizeof(int));
	cout << read << endl;

	file2.close();

	return 0;
}
gerard4143 371 Nearly a Posting Maven

Well I tried to compile your client program and got this...

g++ client.cpp JSTimer.o -Wall -ansi -pedantic -o client

client.cpp:30: error: prototype for ‘Client::Client(const JSTimer&, int)’ does not match any in class ‘Client’
client.cpp:7: error: candidates are: Client::Client(const Client&)
client.cpp:11: error: Client::Client(JSTimer&, int)
client.cpp:25: error: Client::Client()
client.cpp:37: error: prototype for ‘int Client::getArrivalTime() const’ does not match any in class ‘Client’
client.cpp:12: error: candidate is: int Client::getArrivalTime()
client.cpp:42: error: prototype for ‘int Client::getServiceTime() const’ does not match any in class ‘Client’
client.cpp:13: error: candidate is: int Client::getServiceTime()
client.cpp:47: error: no ‘void Client::display(std::ostream&) const’ member function declared in class ‘Client’
client.cpp: In function ‘std::ostream& operator<<(std::ostream&, const Client&)’:
client.cpp:55: error: ‘const class Client’ has no member named ‘display’
client.cpp:56: error: ‘out’ was not declared in this scope

If you correct your errors, I'm pretty sure g++ will link correctly.

gerard4143 371 Nearly a Posting Maven

Just wait and I'll pull out the crystal ball...Yes please post the code.

gerard4143 371 Nearly a Posting Maven

Because both strings, in foo and bar, are string literals they 'may' be stored in the text section(or some read only section) and therefore may be permanent to the process.

gerard4143 371 Nearly a Posting Maven

Could be you freed a pointer *and did not set it to NULL* and then tried to free it again..The message indicates the problem lies at address 0x089b8008

*** glibc detected *** ./tryp: double free or corruption (top): 0x089b8008 ***

moroccanplaya commented: thanks +1
gerard4143 371 Nearly a Posting Maven

Nope, no drawbacks. The this pointer is just a pointer to the data members of the object..If omitted in member functions its assumed.

Should you use it? It really depends on your preference.

gerard4143 371 Nearly a Posting Maven

I'm still a little foggy on the rules for replacing your characters with '@'...What if you had a scenario like below.

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

char ch[2][4] = {{'a', 'a', 'c', 'a'}, {'e', 'f', 'c', 'h'}};

void find_match(char *a , int row, int cols)
{
	int i = 0;
	int j = 0;
	bool foundit = false;

	for (; i < (row * cols); ++i)
	{
		for (j = i + 1; j < (row * cols); ++j)
		{
			if (a[i] == a[j])
			{
				foundit = true;
				a[j] = '@';		
			}		
		}
		if (foundit)
		{
			foundit = false;
			a[i] = '@';
		}
	}
}

int main()
{
	int i = 0, j = 0;
	find_match((char*)ch, 2, 4);

	for (; i < 2; ++i)
	{
		for (j = 0; j < 4; ++j)
		{
			fprintf(stdout, "[%d][%d]->%c\n", i, j, ch[i][j]);
		}
	}

	return 0;
}

output

[0][0]->@
[0][1]->@
[0][2]->@
[0][3]->@
[1][0]->e
[1][1]->f
[1][2]->@
[1][3]->h

gerard4143 371 Nearly a Posting Maven

Your representation of your 2-dim array leaves a lot open for interpretation...Do you mean if you have a 2-dim array like below

{a, b, c, d}{a, f, h, k}

would have a final result

{@, b, c, d}{@, f, h, k}

gerard4143 371 Nearly a Posting Maven

Shouldn't this line be

if((strcmp(first, workers[L].first) == 0) && (strcmp(last, workers[L].last) == 0))

calling strcmp twice.

Also your error...first and last are characters not c-strings.

gerard4143 371 Nearly a Posting Maven

This requires a c string

gets(me.age);//error

not a short.

Here's gets prototype

char *gets(char *s);

Also gets is a dangerous function that should never be used..Here's a short blurb on why.

Never use gets(). Because it is impossible to tell without knowing the
data in advance how many characters gets() will read, and because
gets() will continue to store characters past the end of the buffer, it
is extremely dangerous to use. It has been used to break computer
security. Use fgets() instead.

The functions you should be using are fgets() and fscanf

gerard4143 371 Nearly a Posting Maven

yes.

Your reading from a stream that's opened for writing..

gerard4143 371 Nearly a Posting Maven

So buff is 1024 characters long?

char buff[1024];