I have this:
foo(cons char *p);

foo not is my function, and I don't have access to your source code.

I'm trying use foo so:
char val[32];
foo(val);

The result of foo is zero and not the desired string.

Other tries:
This work:
foo("something here");
This don't work:
foo((cons char *) val);

How I can make this "connversion"?

Note: I'm using pure C, nothing in C++.

Thank You.

what is foo() trying to do that that string? When you say "it doesn't work", what exactly do you mean by that?

what is foo() trying to do that that string? When you say "it doesn't work", what exactly do you mean by that?

Briefly foo() reads the string and put to a file.

Number of questions. The first one. Your variable

char val[32];

Is it delimited with a '\0'?

Number of questions. The first one. Your variable

char val[32];

Is it delimited with a '\0'?

YES.

You code should work if...

the function expects a cstring and your passing a cstring..See below.

#include <stdio.h>

void foo(const char* s)
{
	fputs(s, stdout);
}

int main()
{
	int i = 0;

	char ch[32];

	for (i = 0; i < 26; ++i)
		ch[i] = i + 'a';

	ch[26]  = '\0';

	foo(ch);
	return 0;
}

This code works without incident.

You code should work if...

the function expects a cstring and your passing a cstring..See below.

#include <stdio.h>

void foo(const char* s)
{
	fputs(s, stdout);
}

int main()
{
	int i = 0;

	char ch[32];

	for (i = 0; i < 26; ++i)
		ch[i] = i + 'a';

	ch[26]  = '\0';

	foo(ch);
	return 0;
}

This code works without incident.

No, don't work with "my" foo.

I agree with gerard -- if you program doesn't work then the problem is elsewhere.

No, don't work with "my" foo.

Again -- "don't work" means nothing to us. Is that what you tell your auto mechanic when you need your car fixed?

Again -- "don't work" means nothing to us. Is that what you tell your auto mechanic when you need your car fixed?

You can understand "don't work" as "Write zero on the file, and not the string". OK???
It does not matter what foo does, the question is the "cast".

The cast has nothing to do with the problem. Your code is the problem, since you were given foo() and can not change it. You will have to post the exact code if you expect to get any further help from anyone. Afterall, we can't see your computer's monitor.

Can we see how your populating var[32]?

Can we see how your populating var[32]?

sprintf(var, "%i", counter);
and too:
strcpy(var, "name");

I found the problem. I need of one new var[32] for each foo call.

Told you so :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.