473,385 Members | 1,912 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Help with dd array

what is wrong with my main fn?

void f(char** p)

{

printf("%s", p[0]);

}

void main()

{

char a[50][50];

strcpy(a[0], "hello");

f(a);

}
Nov 25 '05 #1
2 1083

"Singleton" <ku*****@homecall.co.uk> wrote in message
news:43**********@mk-nntp-2.news.uk.tiscali.com...
what is wrong with my main fn?

void f(char** p)

{

printf("%s", p[0]);

}

void main()

{

char a[50][50];

strcpy(a[0], "hello");

f(a);

}


Gosh, it's hard to know where to start ... but maybe you could say something
about what you expect this to be doing?

Something like this ...??

#include <stdlib.h>

void f(char * p)

{
printf("%c", p[0]);
}

int main(void)

{
char a[50][50];

a[0][0] = 'e';

f(&a[0][0]);
}

a is an array of 50 arrays of 50 characters. Is that what you thought it
was?
Nov 25 '05 #2
Singleton said:
what is wrong with my main fn?

void f(char** p)

{

printf("%s", p[0]);
Undefined behaviour - calling a variadic function without a function
prototype in scope. You forgot to #include <stdio.h>

}

void main()
In C, main() returns int.

{

char a[50][50];

strcpy(a[0], "hello");
You'll want <string.h> as well, then.
f(a);


f takes char **, but you're not passing a char **. In a value context, the
name of an array decays into a pointer to its first element, so a has the
type char (*)[50], which is not the same as char **.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Nov 25 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Treetop | last post by:
I am creating a calendar with JavaScript. I want to be able to put date and time in an array and have a calendar display properly with 7 columns. I am stuck at this point. Any help would be...
3
by: Tommy Lang | last post by:
I am working on this project and I need some help/pointers/comments to get me started, I am stuck. The program will be used to store information in an array while it is running. I need to store...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
5
by: ritchie | last post by:
Hi, I am writing to ask if anyone can see why my array is not being sorted correctly? It's an array of 4 elements(ints 1,2,3,4) but after calling the selection sort it comes back sorted as...
27
by: ruel loehr | last post by:
Hey guys, I am looking for some insight: Given two sorted arrays of integers A and B, where array B has enough extra room in it to hold the contents of both A and B. Merge array A and B...
3
by: ash | last post by:
Hey I am new, but I don't have time to intruduce myself yet. I am intro to C++ and this is a programme I have to write. all the direction are here, It will be very nice of someone to figure this...
8
by: intrepid_dw | last post by:
Hello, all. I've created a C# dll that contains, among other things, two functions dealing with byte arrays. The first is a function that returns a byte array, and the other is intended to...
3
by: inkexit | last post by:
I need help figuring out what is wrong with my code. I posted here a few weeks ago with some code about creating self similar melodies in music. The coding style I'm being taught is apparently a...
4
by: mattehz | last post by:
Hey there, I am trying to upload old source files and came across these errors: Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_html.php on line 59...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.