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

Oh if you have a make file then type Make.

gerard4143 371 Nearly a Posting Maven

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

gerard4143 371 Nearly a Posting Maven

If your using GNU's compiler then the compile should be

g++ source.cpp -o executable_name

The errors your receiving indicate that you have two main functions...GNU reduces the main function to _start.

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

so what determines wether it only works for a 64 bit system??

If memory addresses are 64 bit then it'll only work on a 64 bit CPU.

gerard4143 371 Nearly a Posting Maven

so....would a program compiled on a 64bit pc not work for a 32 bit pc?

That really depends since you can create 32 bit PC programs with 64 bit PC compilers.

gerard4143 371 Nearly a Posting Maven

Here's an example to look at. A note the function modifies the original string so it my not be appropriate for your assignment.

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

char ca[] = "this is the string to tryout on our reverser";

void myfunc(char *s)
{
	int i = 0;
	int len = strlen(s);

	for (i = len; i > 0; --i)
	{
		if (s[i] == ' ')
		{
			s[i] = '\0';
			fprintf(stdout, "%s ", (char*)&s[i + 1]);
			myfunc(s);
			return;
		}
	}
	fputs(s, stdout);
}

int main(int argc, char**argv)
{
	myfunc(ca);
	exit(EXIT_SUCCESS);
}
gerard4143 371 Nearly a Posting Maven
moroccanplaya commented: thanks +1
gerard4143 371 Nearly a Posting Maven

Sure try

gcc -O2 -Wall -c foo.c -o yourname.o

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

The one important thing I learned about public forums is...You need thick skin. It just a post, get past it.

gerard4143 371 Nearly a Posting Maven

You might not like the previous posting but its accurate...Your using a pointer that's pointing to nothing..

int main()
{
    process *p;/*this points to nothing*/
    p->pid = 1;
    p->reference_string = "000111222";
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

Try the code below

#include <stdio.h>

int main()
{
	int x = 67;
	fprintf(stdout, "c->%c\n", (char)x);
	fprintf(stdout, "c->%c\n", x);
	return 0;
}
gerard4143 371 Nearly a Posting Maven

O.K.

Your calling your functions incorrectly.

incorrect

count=read_temps(int temps[]);
rec_temps=hot_days(int count,int temps[]);

try this, I say try because I don't have the prototypes for the functions and I'm guessing that this is correct.

count=read_temps(temps);
rec_temps=hot_days(count, temps);
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

This line has an extra )

int count,rec_temp[]);

gerard4143 371 Nearly a Posting Maven

I use neither! I use Gedit for C programming and Kdevelop for C++....Why? IMHO, Kdevelop is the best/simplest IDE out there. Plus I really appreciate Kdevelop's code completion algorithm.

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

i want to put name for the query like this for e.g

chr* names;

names=mysql_query(con,"the query");

so names now = to the query result thats what i want to do!!! did u get me now?

Well if you looked at the code I posted, you would have noted that I used a pointer to MYSQL_RES to hold the result for the connection.

Please read this link, it will explain what mysql_query returns..

http://dev.mysql.com/doc/refman/5.0/en/mysql-query.html

gerard4143 371 Nearly a Posting Maven

I'm not sure what you mean by "set a variable for the query"? Do you want to pass a variable to the query or do you want to receive the results from a query?

gerard4143 371 Nearly a Posting Maven

Wow..You really should download a tutorial on mysql. You haven't established a valid connection to your database, yet your preforming a query on it...Here's a brief example

#include <mysql/mysql.h>
#include <stdio.h>

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

char server[] = "localhost";
char user[] = "root";
char password[] = ""; 
char database[] = "testdb";

conn = mysql_init(NULL);/*initialize*/

/* Connect to database */
if (!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0)) 
{
	printf("an error occurred->%s\n", mysql_error(conn));
	return 1;
}
/*perform query*/
if (mysql_query(conn, "select * from personal"))
{
	printf ("the query result->%s\n", mysql_error(conn));
	return 1;
}

/*get query result*/
res = mysql_use_result(conn);

/*print result*/
while ((row = mysql_fetch_row(res)) != NULL)
	printf("%s, %s, %s, %s, %s, %s \n", row[0], row[1], row[2], row[3], row[4], row[5]);

/* close connection */
mysql_free_result(res);
mysql_close(conn);
return 0;
}
jonsca commented: Nice example. +5
gerard4143 371 Nearly a Posting Maven

If you look at the prototype of sprintf

int sprintf(char *str, const char *format, ...);

You'll note that the first argument is a char *str...your passing a character on line 78

sprintf(temp_out, "%d", cene);

temp_out is a character.

You might be able to get away with something like below where you'll pass the character array from address starting from temp_out.

sprintf(&temp_out, "%d", cene);

but I really doubt that's what your after.

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

segmentation fault results from trying to read/write from/to an invalid address..

Here's what happens when fgets() encounters the end of file or an error...Quote from my man files

"char *fgets(char *s, int size, FILE *stream);

gets() and fgets() return s on success, and NULL on error or when end
of file occurs while no characters have been read."

Could you post your code so we could have a look at it.

gerard4143 371 Nearly a Posting Maven

Its been some time since I looked at pipes so I would go over this code with a fine tooth comb...You'll probably find places in the code that need improvement.

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

enum PIPES {READ, WRITE};

int main(int argc, char**argv)
{
	char ch[] = "This is the message to pass along to the end\n";
	int hpipe[2];

	pipe(hpipe);

	if (fork())
	{
		close(hpipe[READ]);
		write(hpipe[WRITE], ch, strlen(ch));
		close(hpipe[WRITE]);		
	}
	else
	{

		if (fork())
		{
			/*does nothing*/	
		}
		else
		{
			char final[2];
			int n = 0;
			close(hpipe[WRITE]);
			while ((n = read(hpipe[READ], final, 1)) > 0)
			{
				final[n] = '\0';
				fputs("->", stdout);
				fputs(final, stdout);
				fputs("\n", stdout);				
			}
			close(hpipe[READ]);
		}
	}
	exit(EXIT_SUCCESS);
}
gerard4143 371 Nearly a Posting Maven

I quickly looked at your 'addMyString' function...Your adding the character before you check the capacity. Shouldn't it be the other way around?

gerard4143 371 Nearly a Posting Maven

Where's the code that copies the data?

gerard4143 371 Nearly a Posting Maven

@Adak

Why are you recommending

#define LONG 8
#define INT 4
#define SHORT 2

instead of the compile time sizeof operator?

gerard4143 371 Nearly a Posting Maven

Try adding this

void mainmenu ();

on line 28.

gerard4143 371 Nearly a Posting Maven

Just set the pointer to NULL.

void *vptr = (void*)NULL;

You should get into a habit of initializing all pointers to NULL and all freed pointers to NULL.

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

Its pretty straight forward

#include <stdio.h>
#include <math.h>

int main()
{
	double val = 123.33;

	fprintf(stdout, "rounded->%d\n", lround(val/10.0) * 10);
	return 0;
}
gerard4143 371 Nearly a Posting Maven

Not sure why you have fifty of everything...

char name[50][50];

Why don't you create an array of structures instead of hard coding fifty elements into your structure members.

DETAILS dt[50];

gerard4143 371 Nearly a Posting Maven

Ooops please remove this one.

gerard4143 371 Nearly a Posting Maven

You have i < (i + p)...unless p is negative(or becomes negative) you'll never exit you for loop.

gerard4143 371 Nearly a Posting Maven

You can add it to the project so it can reside with the exe.

gerard4143 371 Nearly a Posting Maven

Shouldn't your path be

"c:\word"

gerard4143 371 Nearly a Posting Maven

What happens here when i == 0

average = sum/i

also this

printf(" Input Numbers (enter -1 to end):\n");
           scanf( "%d", &a[SIZE]);

doesn't do what you think it does...Currently this code inputs a value past the end of the array a.

gerard4143 371 Nearly a Posting Maven

Try initializing these values

int sum = 0;
int average = 0;
int num = 0;
int i = 0;

also

scanf( "%d", &a[SIZE]);