gerard4143 371 Nearly a Posting Maven

Try including the header file stdio.h

gerard4143 371 Nearly a Posting Maven

Could you post the program...

gerard4143 371 Nearly a Posting Maven

There is an old saying -- "garbage in, garbage out". What you posted is not even C code. I don't know what it is, but he certainly isn't C or C++ languages.

That would be the output of the GNU gdb (debugger)....And yes C does blow sometimes.

Maybe if you posted the code we could make sense of this.

gerard4143 371 Nearly a Posting Maven

AD, thanks for the help. I'm still having trouble understanding the first part though. Could you explain how (int *)(pc+i)== pa + 3 yields i = 12?

I quickly looked at your posting and have one question

int *pa=arr

What's arr?

gerard4143 371 Nearly a Posting Maven

Here's an interesting link that may clear this up:

http://en.wikipedia.org/wiki/.bss

gerard4143 371 Nearly a Posting Maven

I not sure where your getting your information from but its old. Try this link:

http://tldp.org/LDP/lkmpg/2.6/html/

gerard4143 371 Nearly a Posting Maven

@ Ancient Dragon, if both are same,why is there a difference in code size in both cases. The initialization of global variables happens before the main() takes off, loosly at the startup. Isn't it?

Please read Ancient Dragon's post for the answer.

gerard4143 371 Nearly a Posting Maven

thank


char buffer[8]={0x72, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

If your using C strings them the above shouldn't work...

0x00 is not equal to '0'

0x30 is equal to '0

Check out this link for ascii table conversions

http://www.google.ca/imgres?imgurl=http://www.cs.utk.edu/~pham/ascii_table.jpg&imgrefurl=http://www.cs.utk.edu/~pham/ascii.html&h=475&w=715&sz=142&tbnid=fHeK-W8VD8qXUM:&tbnh=93&tbnw=140&prev=/images%3Fq%3Dascii%2Btable&hl=en&usg=__SejXXWEBQhMmL66GziQUEWyCjIM=&sa=X&ei=jhE7TI6fFo2inQfEpIXgAw&ved=0CCsQ9QEwAw

gerard4143 371 Nearly a Posting Maven

Try strtol()

long int strtol(const char *nptr, char **endptr, int base);

DESCRIPTION
The strtol() function converts the initial part of the string in nptr
to a long integer value according to the given base, which must be
between 2 and 36 inclusive, or be the special value 0.

gerard4143 371 Nearly a Posting Maven
gerard4143 371 Nearly a Posting Maven

Sounds like homework...Is it?

gerard4143 371 Nearly a Posting Maven

thanks. I realized it after i posted it. I just can't add two char pointers/strings. I have to used the function strcat(str1, str2), right?

Well if you want to append one string onto another, then yes use strcat.

gerard4143 371 Nearly a Posting Maven

The problem...your trying to add two char pointers...I think.

Could you post the rest of the code.

gerard4143 371 Nearly a Posting Maven

with what ? :)) program in c that has math and using for loop . can u give me some source codes of this program .?

If your looking for source code then google. If you have a specific question about a C program please post it.

gerard4143 371 Nearly a Posting Maven

Help you....With what?

gerard4143 371 Nearly a Posting Maven

Why don't you try it and find out...

gerard4143 371 Nearly a Posting Maven

This is what my help files say about fgets return value...

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.

gerard4143 371 Nearly a Posting Maven

You may want to investigate conio.h or curese.h libraries for this behaviour.

MosaicFuneral commented: No one sane should be using those relics. -1
gerard4143 371 Nearly a Posting Maven

When a function returns, it uses whatever is in the %rax register as its return value. Your function may inadvertently be placing the right value in %rax.

Note: I won't rely on this behaviour.

gerard4143 371 Nearly a Posting Maven

Woah...Don't use gets(). You run the risk of a buffer overflow, instead use fgets().

gerard4143 371 Nearly a Posting Maven

I would Google RPC - Remote Procedure Call.

http://en.wikipedia.org/wiki/Remote_procedure_call

gerard4143 371 Nearly a Posting Maven

Hello

I am sorry if this is a dumb question but is it conceivable to determine the memory address of a function that is inside a running application from another application? Say I have an application A that has a function helloWorld(). A is being launched. I would like to do an application B which when run would call helloWorld() from application A if it happens to be running. Thanks for helping

Yohan

You didn't provide enough information....What operating system? Plus could you give us an example of the source code for both process A and process B.

gerard4143 371 Nearly a Posting Maven

Well if you need to map the file's contents into the user's address space, then use mmap().

gerard4143 371 Nearly a Posting Maven

Myself, I've always preferred a simple editor like Gedit or Vim.

gerard4143 371 Nearly a Posting Maven

Are you looking for Linux/Unix's ncures.h file?

http://math.hws.edu/orr/s04/cpsc225/curses.html

gerard4143 371 Nearly a Posting Maven

I found some old...old...old code I had. My apologizes to the language lawyers out there...

server.c

#include <stdio.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/types.h>
#include <signal.h>
#include <unistd.h>

int main(int argc, char**argv)
{
	const int DEFAULT_PROTOCOL = 0;
	void *myvoid;
	char ch[] = "this is the server socket message!\n";
	int serverfd, serverlen, clientfd, clientlen;
	struct sockaddr_un serverunixaddress;
	struct sockaddr_un clientunixaddress;

	signal (SIGCHLD, SIG_IGN);

	struct sockaddr* serversockaddr;
	struct sockaddr* clientsockaddr;

	myvoid = &serverunixaddress;
	serversockaddr = (struct sockaddr*)(myvoid);
	serverlen = sizeof(serverunixaddress);

	myvoid = &clientunixaddress;
	clientsockaddr = (struct sockaddr*)(myvoid);
	clientlen = sizeof(clientunixaddress);

	serverfd = socket (AF_UNIX, SOCK_STREAM, DEFAULT_PROTOCOL);

	serverunixaddress.sun_family = AF_UNIX;
	strcpy(serverunixaddress.sun_path, "thesocket");

	unlink ("thesocket");

	bind (serverfd, serversockaddr, serverlen);

	listen (serverfd, 5);

	while (true)
	{
		clientfd = accept (serverfd, clientsockaddr, (socklen_t*)&clientlen);

		if (fork())
		{
			close (clientfd);
		}
		else
		{
			for (int i = 0; i < 1000; ++i)
				write (clientfd, ch, sizeof(ch));
			close (clientfd);
			return 0;
		}
	}
	
	return 0;
}

client.c

#include <stdio.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/types.h>
#include <unistd.h>

int main (int argc, char**argv)
{
	const int DEFAULT_PROTOCOL = 0;
	void *myvoid;
	char ch;
	int serverlen, clientfd, result, numread;
	struct sockaddr_un serverunixaddress;
	struct sockaddr* serversockaddr;

	myvoid = &serverunixaddress;
	serversockaddr = (struct sockaddr*)(myvoid);
	serverlen = sizeof(serverunixaddress);

	clientfd = socket (AF_UNIX, SOCK_STREAM, DEFAULT_PROTOCOL);
	
	serverunixaddress.sun_family = AF_UNIX;
	strcpy(serverunixaddress.sun_path, "thesocket");
	do
	{
		result = connect(clientfd, serversockaddr, serverlen);
		if (result == -1) sleep(1);
	}
	while (result == -1);
	do
	{
		numread = read(clientfd, (char*)&ch, sizeof(char));
		fputc(ch, stdout);
	}
	while (numread > 0);
	close (clientfd);
	return 0;
}

This should give you a …

gerard4143 371 Nearly a Posting Maven

It is basically going to only be executed by the user from the local machine. Where would be a good place to look for help with the 'local namespace socket'

You'll notice from this link:

http://www.gnu.org/s/libc/manual/html_node/Local-Namespace-Details.html#Local-Namespace-Details

That Unix sockets and local namespace socket are the same thing...

gerard4143 371 Nearly a Posting Maven

Or maybe send it through a local namespace socket???

The availability of your daemon really depends on your design criteria. If you want it available to the local machine only then yes explore the 'local namespace socket' or maybe unix sockets...If you want the daemon to be available to remote apps then you'll have to explore TCP/UDP sockets.

gerard4143 371 Nearly a Posting Maven

Here's probably the best(free) ebook on asm for Nasm/Linux

http://www.drpaulcarter.com/pcasm/

gerard4143 371 Nearly a Posting Maven

Thanks a lot gerard. How would i communicate between the daemon and the user?? I know via the shell, but how would the daemon get the cmd?? Is the file method I suggested a good place to start?

If you want the process to run in the background independent of other processes then yes, this is a good starting place....

For communicating I would choose TCP sockets, having the daemon waiting in the background for a command to be received on its designated port.

If you use TCP sockets+daemon in this manner then you can pass the file and path to the daemon and have it act on the contents of the file....Just a suggestion.

gerard4143 371 Nearly a Posting Maven

Ok, well what about in *nix?? Wouldn't a way to achieve this is to have the program in the background to be looking for a file, that the other program will create with the command. If it finds a file, it opens it extracts the command and performs it. Is this a efficient way of doing this??

What your talking about is a daemon..Here's a link on creating daemons.

http://www.netzmafia.de/skripten/unix/linux-daemon-howto.html

gerard4143 371 Nearly a Posting Maven

I want to add that i cant use if or while function

You should be posting in the Java section not the C section.

gerard4143 371 Nearly a Posting Maven

Yeah...I would say your in the wrong section

gerard4143 371 Nearly a Posting Maven
Ancient Dragon commented: Very useful link :) +28
gerard4143 371 Nearly a Posting Maven

If your looking for the code with no effort then Google, the web has all kinds of examples out there for the taking.
If you require help getting your code working, then please post what you have so far and we'll have a look at it...

gerard4143 371 Nearly a Posting Maven

Hi ...
i am doin my B.E in computer science amd i was asked to write a programme ...
can anyone help me write a c program that can hang the system ... and can u also tel me how to set it right again...:icon_neutral: and can u tel me how to use the debug option ... pl pl. plzzzzzzzz......

The operative phrase here is "i was asked to write a programme ..." meaning you...So what do you have so far?

gerard4143 371 Nearly a Posting Maven

hi guys

is it timeconsuming to use memset instead of for?

i mean suppose we have an array of int

int prime[200000];

we use memeset(prime, 200000, 0, sizeof(prime))

also we can use
for(i = 0; i < 200000; i++)
prime = 0;

I would expect memset() to be optimized for the machine it was compiled on...

gerard4143 371 Nearly a Posting Maven

I tried compiling your program and got numerous errors

test.c:4:1: warning: return type defaults to ‘int’
test.c: In function ‘main’:
test.c:19:2: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char (*)[50]’
test.c:36:2: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char (*)[10]’
test.c:52:4: warning: unknown conversion type character ‘.’ in format
test.c:52:4: warning: too many arguments for format
test.c:58:4: warning: unknown conversion type character ‘.’ in format
test.c:58:4: warning: too many arguments for format
test.c:86:2: warning: unknown conversion type character ‘.’ in format
test.c:86:2: warning: too many arguments for format
test.c:86:7: warning: ‘cashTendred’ is used uninitialized in this function

This is one of your errors:

scanf("%s", &address);

It should be

scanf("%s", address);

Which is discouraged. Try using fgets() instead.

gerard4143 371 Nearly a Posting Maven

You should find all you need in this link:

http://www.lysator.liu.se/c/bwk-tutor.html

gerard4143 371 Nearly a Posting Maven

i know how to make an octal presentation.

u can do while (n1<0777777) and it would give an octal presentation

but how do i make those octal numbers , which are decimal 32767. reach 777777

i am a bit confused,

i need a simple code, nothing difficult. i need to reach 77777 octal figure

from 0 to 77777 octal figure.

the question is whether my code is okay?!?
or do i need something to make it clear

Number one - the numbers are integers not decimal
Number two - 077777 is 32767...How you want to display it is your business.

gerard4143 371 Nearly a Posting Maven

If you need to display octal numbers then look at the code below:

#include <stdio.h>

int main(int argc, char**argv)
{
	fprintf(stdout, "ans->%o\n", 9999);
	return 0;
}
gerard4143 371 Nearly a Posting Maven

In C octal numbers start with a zero like

01234;

gerard4143 371 Nearly a Posting Maven

bst.h

Is a header file. You don't compile header files.

If your looking for the process, creating a library, you should state for which operating system and compiler and type of library.

gerard4143 371 Nearly a Posting Maven

Language specification (aka. standard) is NOT the same as language implementation (by compiler or interpreter).
http://en.wikipedia.org/wiki/Programming_language_specification
http://en.wikipedia.org/wiki/Programming_language_implementation
So - C standard does not *implement* anything, it just defines standard. And How standard will be implemented concretely by compiler/interpreter is only an implementer business.

Jeez, thanks for clearing that up...

gerard4143 371 Nearly a Posting Maven

try this

printf ("value : %u\n", *(unsigned char*)(p + i));

This will cast and dereference a byte starting at p + i...You had casting and dereferencing an int starting at p + i which will overflow past n = 0x000000ff.

gerard4143 371 Nearly a Posting Maven

That is a question for the comp.std.c newsgroup. It is probably because of existing compilers when the standard was written. Without breaking programs, concessions needed to be made.

For me, its enough to know it exists...Thanks for the replies...in first and third person...Gerard4143

gerard4143 371 Nearly a Posting Maven

Now the important question....Why does the C standard implement this type of behaviour or is it better left unknown?

gerard4143 371 Nearly a Posting Maven

Ed would say that there is no difference because the whims of the compiler are irrelevant when it comes to the validity of a program. The program *has* to behave a certain way, regardless of how the compiler makes it happen.

Its relevant to me....and here's a link about referring to yourself in the third person

http://uncyclopedia.wikia.com/wiki/HowTo:Refer_to_Yourself_in_the_Third_Person

gerard4143 371 Nearly a Posting Maven

> I ask because the compiled instructions are not the same...
The C standard does not impose any requirements on intermediate assembly or machine code. As long as the "as if" rule is maintained, the compiler can do anything it wants under the hood.

So....By the same, do you mean C treats them the same and the compiler handles the difference for you?

gerard4143 371 Nearly a Posting Maven

> Why does a C program treat a function call to a function and a function call to a function pointer the same?
Because they *are* the same. :)

By the same, do you mean C treats them the same and handles the difference for you? I ask because the compiled instructions are not the same...

Here's what I'm getting at:

40058d:	48 c7 45 f8 54 05 40 	movq   $0x400554,-0x8(%rbp)
400594:	00 
400595:	e8 ba ff ff ff       	callq  400554 <myfunc>
40059a:	48 8b 45 f8          	mov    -0x8(%rbp),%rax
40059e:	ff d0                	callq  *%rax

Line 0x400595 is the first function call
and lines 0x40059a and 0x40059e are the second.