gerard4143 371 Nearly a Posting Maven

I think this is what you want: - Note your code generates a memory leak on line 43...

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


struct test
{
    int data;
    struct test *link;
};

void change(struct test **ptr);

int main()
{
	struct test *fresh = (struct test *)malloc(sizeof(struct test));

	int some_data = 10;

	fresh -> data = some_data;
	fresh -> link = NULL;

	printf("\n\n\tBefore Going Into Function");

	printf("\n\n\tData = %d\t\tAddress %p", fresh -> data, (void*)fresh);
	printf("\n\n\t____________________________________________________________");

	change(&fresh);

	printf("\n\n\tAfter Getting Out Of Function");

	printf("\n\n\tData = %d\t\tAddress %p", fresh -> data, (void*)fresh);
	printf("\n\n\t____________________________________________________________");

	return 0;
}

void change(struct test **some_ptr)
{
	int some_new_data = 20;

	struct test *new_fresh = (struct test *)malloc(sizeof(struct test));

	*some_ptr = new_fresh;

	/*(*some_ptr) -> data = some_new_data;
	(*some_ptr) -> link = NULL;*/
	new_fresh->data = some_new_data;
	new_fresh->link = NULL;  

	printf("\n\n\tInside Function");
	printf("\n\n\tData = %d\t\tAddress %p", new_fresh -> data, (void*)new_fresh);
	printf("\n\n\t____________________________________________________________");
}
gerard4143 371 Nearly a Posting Maven

You really should be able to do this with one while loop and one for loop. The while loop reads the file and the for loop takes care of the number of entries.

I tried playing with your code and came up with this, its hard coded to a four digit code - for example when prompted the user enters a 4 digit number code, say 3267 which will print the first entry 3 times and the second entry 2 times and the third entry 6 times and finally the fourth entry 7 times...Now this piece of code is very limited in that each entry can only have the values 0 - 9, If you try a two digit value then the code breaks down...

It a nice demo on how to use the while to read the file and the for loop to handle how many times to write

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

int main() 
{
	FILE *fileread,*fileprint;
	char filestr[10];
	int tnum = 0;
	int multi = 1000;
	int i = 0;

	if (!( fileread = fopen("datafile.txt", "r")))
	{
		printf ("**** datafile could not be opened.\n");
		exit(EXIT_FAILURE);
	}

	if (!(fileprint = fopen ("copiesdata.txt", "w+")))
	{
		printf ("**** copiesdata could not be opened.\n");
		exit(EXIT_FAILURE);
	}


	fputs("enter the 4 digit number code->", stdout);
	fscanf(stdin, "%d", &tnum);
	

	while ((fscanf(fileread, "%s", &filestr[0])) != EOF)
	{
		for (i = 0; i < (tnum - (tnum % multi))/multi; ++i)
			fprintf(fileprint, "%s\n",filestr);

		tnum -= (tnum - (tnum % multi));
		multi /= 10;
	} …
me_roy commented: nice alternative +2
gerard4143 371 Nearly a Posting Maven

uh-ooh you aroused the 'C decency committee'

gerard4143 371 Nearly a Posting Maven

Because with virtual memory every user process gets the same address range but different physical memory links...so every process appears to have the same memory but in reality it has its own copy of things like data...Note: most programs will shared some blocks of code i.e. Dlls and the text section of code can be shared..

As an experiment try changing the child processes x value and then display it....add x to the pid and then display it

ithelp commented: Thanks. +6
gerard4143 371 Nearly a Posting Maven

I would investigate the functions strtok() and strtof(), strtod(), strtold().

gerard4143 371 Nearly a Posting Maven

I tried single quotes in your quoted string...it appears to work

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

int main ()
{
	char *ca;
	char queryStringSet[100];
	char command[100];  

	strcpy (command, "export QUERY_STRING=");
	strcpy (queryStringSet, "'a=1&b=2&c=3'");
	strcat (command, queryStringSet);

	printf ("command = %s\n", command);  
	system (command);  

	ca = getenv ("QUERY_STRING"); 
	printf ("QUERY_STRING = %s\n", ca);

	return 0;
}
VernonDozier commented: Thanks. +10
gerard4143 371 Nearly a Posting Maven

Or you could use UDP instead of TCP.
TCP doesn't guarantee packet data size only that it will get delivered in order...like you said if you want to extract individual messages then you'll have to figure out an application protocol to handle it..

gerard4143 371 Nearly a Posting Maven

shouldn't this

sscanf(buffer, "%lf", tempFinal

be

sscanf(buffer, "%lf", &tempFinal
Iamthedude commented: Thanks for the help +0
gerard4143 371 Nearly a Posting Maven

My question is Y DLL? i know that it saves memory and many process can use 1 DLL file at a time blah blah blah......

but is there any task which can not b achieved without using DLL files?? Please reply in details.

I never understood the logic or lack of it in postings like these...You asked questions like - "My question is Y DLL?" and have statements like "can not b achieved" and "blah blah blah......" and you expect a coherent reply with details.

gerard4143 371 Nearly a Posting Maven

I never used SQLite3 but I'm going to say yes because when I googled SqLite3 it said this...

Cross-platform C library that implements a self-contained, embeddable, zero-configuration SQL database engine. The site offers user and developer ...

Why would you need C wrapper functions for a C library?

gerard4143 371 Nearly a Posting Maven

Are you kidding...narrow it down to an operating system plus area of programming..

gerard4143 371 Nearly a Posting Maven

I think this is what you want:

main.c

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

#define APP_PATH "/path_to_testit/testit"

int main(int argc, char**argv)
{
	if (fork())
	{
		fprintf(stdout, "parent pid->%d\n", getpid());
	}
	else
	{
		execlp(APP_PATH, APP_PATH, "some value");
	}
	exit(EXIT_SUCCESS);
}

testit.c

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

int main(int argc, char**argv)
{
	fprintf(stdout, "we passed->%s\n", argv[1]);
	fprintf(stdout, "client's parent->%d\n", getppid());
	exit(EXIT_SUCCESS);
}
gerard4143 371 Nearly a Posting Maven

Try this, you had a typo in your array - 'a','b','c','e','d','e','f','g' - giving you excess elements plus a few more errors

#include <stdio.h>

int main(int argc, char** argv)
{
	char c[999];
	char alpha[2][26]={{'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'},{'a','b','c','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}};
	int pos[26];
	int i=0;
	for(i=0;i<26;i++)
	{
		printf("%c\n",alpha[0][i]);
	}
	return 0;
}
gerard4143 371 Nearly a Posting Maven

Tried adding some data...or functions in this case

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

char ch[] = "this is the string!\n";

typedef char* (*firstptr)(void);
typedef firstptr (*secondptr)(void);

char* retstr(void)
{
	return ch;
}

firstptr retfunc(void)
{
	return retstr;
}

int main(int argc, char**argv)
{
	secondptr myarray[10];
	myarray[0] = retfunc;
	fprintf(stdout, "ch->%s\n", ((firstptr)myarray[0]())());

	exit(EXIT_SUCCESS);
}

The output:
ch->this is the string!

Salem commented: Very nice, using a couple of intermediate typedefs +19
gerard4143 371 Nearly a Posting Maven

Could you show us what you have so far...

Salem commented: They just did! ;) It's just not enough. +18
gerard4143 371 Nearly a Posting Maven
gerard4143 371 Nearly a Posting Maven

Thanks for the reply,

But I still have one question: how can you explain the fact that you can fill the array this way?:

struct my_struct my_array[] = {
    { TYPEA },
    { TYPEB }
  };

without nothing for the data field?

And the one reason I needed pointers to structures, is to be able to call them to get a size, and not fill them immediately. Do you think that can be done with this method?

If that's a problem then try:

struct my_struct my_array[] = {
    { TYPEA, NULL },
    { TYPEB, NULL }
  };
gerard4143 371 Nearly a Posting Maven

Number - 2
the main function returns the address of main as its exit value..

gerard4143 371 Nearly a Posting Maven

What is going on here. Copy this C code , compile and run. What do you think is going on? Note I don't want the answer, I know what's going on here. This is just something for the rookies to play with...

Also this is not the best way to write code...

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

int* myint(void)
{
	static int myint = 9;
	fprintf(stdout, "myint now equals->%d\n", myint);
	return &myint;
}

int main(int argc, char**argv)
{
	*(myint()) = 12356;
	myint();

	exit(EXIT_SUCCESS);
}
gerard4143 371 Nearly a Posting Maven

Basically what is the system level difference between language C and C++ ?

Could you give us an example of what you mean by system level.

gerard4143 371 Nearly a Posting Maven

Rules:
• Please solve it on your own/submit your own solution.

What don't you understand about the above rule?

gerard4143 371 Nearly a Posting Maven

Yes, of course I accept that.. but I'm just learning C and I'm in a bad situation now (no time), so if someone could help me.. it will be great.

anyway, I'm trying to write it alone.. :(

The best thing you could do is post what you have so far and state where your having problems....

gerard4143 371 Nearly a Posting Maven
tux4life commented: Good link :) +6
gerard4143 371 Nearly a Posting Maven

>> I believe no questions are stupid.
That's naive. And I didn't say the questions was stupid. I said the thread was stupid.

How many times does the same thing have to be said before it's registered?

Gerard -- "The include statement is processed by the preprocessor so it can't be dynamically created in the executable..."
Dave Sinkula -- "The #include directive is like a copy-and-paste that happens at compile time. You can't do it at runtime."
AD -- "No because the #inc lude directive is processed at compile time, not runtime."
Me (Ironically) >> The #include thing only works on compile time. Not run time.

Then you finally say -- "The #include thing only works on compile time. Not run time" - so you mean the binary will have all the contents of the the included file???

Its undeniable, the point you make.

gerard4143 371 Nearly a Posting Maven

Not really sure what your question is...well beside the main homework question..

gerard4143 371 Nearly a Posting Maven

Try defining your string "instruction" like below...
Also if you have errors in the future could you post them

/* Libraries */
#include <stdio.h>
#include <string.h>

char instruction[] = "add  h'13', 4";//not a constant now

/* Main Function */
int main()
{
	/* Declarations */
    
    char *action;
    char *number;
    char *number2;
    
    printf("%s \n",instruction);

// The run time error occurs here

    action = strtok ( instruction, " " );
   number = strtok ( NULL, " ' " );
number2 = strtok ( NULL, "," );

	printf("%s \n %s \n %s \n", action, number, number2);

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

Try this link...it has it all broken down

http://makepp.sourceforge.net/1.19/makepp_tutorial.html

Aia commented: Good link +7
gerard4143 371 Nearly a Posting Maven

This is line 111

height_earth = double distance_earth(float speed, double radians)* (tan(radians)) - (G_earth * (pow(double distance_earth(float speed, double radians), 2))) / ((2(pow((speed)(cos(radians), 2)))));

should probably be:

height_earth = distance_earth(speed, radians)* (tan(radians)) - (G_earth * (pow(distance_earth(speed, radians), 2))) / ((2(pow((speed)(cos(radians), 2)))));
A Tripolation commented: thanks man +1
gerard4143 371 Nearly a Posting Maven

I'm looking at you main function I can't see where your calling any function to initialize your array.

shouldn't you be calling
void init_board();
void print_board()

yellowSnow commented: A good and fast response. +2
gerard4143 371 Nearly a Posting Maven

it's an assignement and i have to get info about kernel in unix hows it works ...

Did you read the first reply I posted?

gerard4143 371 Nearly a Posting Maven

thx plz i cant find it
can someone help

Maybe if you explained t us what "it" is...

gerard4143 371 Nearly a Posting Maven

plz plz urgent im a beginner in unix.
can someone reply asap .
what are kernel modules?what role do they plan in building and runnig a kernel?what happens if the linux kernel did not support modules?

Here's a good link to get you started

http://tldp.org/HOWTO/Module-HOWTO/

gerard4143 371 Nearly a Posting Maven

If your looking for the source code for Linux system calls then download the kernel source code for your Linux distro and you'll find it there...The first file you want to investigate is - Entry.S - this file has all the code for the interrupt/syscall call that handles the dispatch....

Also this link may shed some light

http://asm.sourceforge.net/syscall.html#p3

Gaiety commented: its so nice of you +1
gerard4143 371 Nearly a Posting Maven

So you want us to Google for you

gerard4143 371 Nearly a Posting Maven

I have no idea why your launching above your tank but you really should be using pygame to handle the graphics...

If you can't find any answers then build a projectile log that will log every position the shell has. With this you have a very good diagnostic tool plus you'll be able to tweak your physics...

gerard4143 371 Nearly a Posting Maven

If you want to see how other language's handle function overloading, try Googling "name mangling" and you'll see the compiler just renames or mangles the said functions names according to some scheme based on the parameter types...

gerard4143 371 Nearly a Posting Maven

Are you talking about stripping the functionality(assem code) out of a cpp file and inserting it into another cpp file? I guess what I'm asking is...what are you trying to do?

gerard4143 371 Nearly a Posting Maven

Lol, thank you! :)

I feel silly now :P

Don't, assembly can be a hard step to make...Just remember your dealing with either addresses or numbers...Gerard4143

gerard4143 371 Nearly a Posting Maven

C can be transfered to different machines because the standard library abstracts away may of these details...i.e. The language is the same but each machine gets its own standard library to handle these details. So when you transfer source code between machines and recompile the standard library makes sure everything lines up for that machine...

gerard4143 371 Nearly a Posting Maven

Give me money

gerard4143 371 Nearly a Posting Maven

Yeah so what's the problem? Try reading the file back into a structure Person like:

struct Person pread;

for( i = 0; i < 2; i++ )
  {
      read(x, (char*)&pread, sizeof(struct Person));
      fprintf(stdout, "name->%s\n", pread.name);
      fprintf(stdout, "address->%s\n", pread.address);
  }

and you'll find your data's all there and intact

gerard4143 371 Nearly a Posting Maven

That's because your writing the binary/hex value of the integer and not its ascii text representation...

The best way to read and write a structure is to write the structure all at once i.e.

struct person 
{

};

struct person Person;

write(fd, (char*)&person, sizeof(struct person));
read(fd, (char*)&person), sizeof(struct person));
gerard4143 371 Nearly a Posting Maven

Well Linux has a few - Code::Blocks, Gedit, Kwrite, KDevelope, Gvim and so on. Myself I'm fond of Vim/GVim

jbennet commented: quick reply +36
gerard4143 371 Nearly a Posting Maven

First random by function is not random...no matter what they call the function it is predictable...

Second you really should read up on this field "encryption", its big and diverse I doubt you came up with a new idea..

I really hate to busting bubbles but the truth is encryption is a very complex art that usually requires extensive training in mathematics and/or computer science(Master or Phd)

gerard4143 371 Nearly a Posting Maven

If you look on the main C++ page in Daniweb you will see a posting "How do I flush the input stream".
This should help

Roebuc commented: Thank you for pointing me to that thread. +1