473,396 Members | 1,935 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,396 software developers and data experts.

assigning pointer to a string array

I icreated a two-dimensional array in which i placed two stack of cards. One is numerical and one is random. Then i created two sets of strings which i tried to assign to the cards so I could print them out. I was able to give the initalized cards a pointer to their address in a loop. Outside the loop I created a function where I placed my strings but I can't get the code right to give the strings to the address of the cards i pre-initialized.


for (int i=0; i<frags; i++)
{
story[i][0] = i + 1; //here is where i initialized the deck and
story[i][1] = rand(); // set the pointer to the address
p1[i][0] = &story[i][0];
p1[i][1] = &story[i][1];
}

Assign1(num);




//i called assign1 but cant figure how to
//match the sent. to init. numbers outside
//or inside the subroutine


void Assign1(int num)
{ .
static char *sen[20] = {
"the farmer drove to the city"
"the brakes were slipping"
"the road got very wet"
"water ran down the hill"
"potatoes spilled everywhere"
"she laid an egg"
"the feathers went flying"
"the duck went straight up in the air"
"the dog ran quickly after it"
"everything was planted last spring"
"the clock seemed to tick faster"
"flowers will sprout soon"
"the black cat crossed in front"
"some hay fell off the truch"
"martians landed in my cereal"
"you can't spell dumbass without ass"
"the truck went faster"
"wheel fell off the right side"
"the jester was entertaining the court\n"
"a plane flew overhead"
};

static char *add[15] = {
"when",
"in order that",
"because",
"after",
"although",
"as long as",
"since",
"even though",
"so that",
"while",
"including",
"except",
"such as",
"in addition to"
};

}

inti file looked like this
Original Deck
10112
16597
237
23820
29036
72
23854
8636
6974
3686
13911
6395
1430
22111
25511

Element
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Oct 26 '08 #1
2 3477
boxfish
469 Expert 256MB
Could you please explain what you're trying to get your program to do? What's a card and how can you assign a string to it? Assign1 isn't going to work, because sen is local to that function and so can only be accessed within it. I suggest making sen a global constant. But I don't understand your code. What does the loop do and what are the random numbers for?
Thanks,
Good luck,
And...
Please use code tags around your code. Put [CODE] before it and [/CODE] after it so it shows up in a code box and the indentation isn't wrecked. Thanks.
Oct 27 '08 #2
donbock
2,426 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. static char *sen[20] = {
  2. "the farmer drove to the city"
  3. "the brakes were slipping"
  4. "the road got very wet"
  5. "water ran down the hill"
  6. "potatoes spilled everywhere"
  7. "she laid an egg"
  8. "the feathers went flying"
  9. "the duck went straight up in the air"
  10. "the dog ran quickly after it"
  11. "everything was planted last spring"
  12. "the clock seemed to tick faster"
  13. "flowers will sprout soon"
  14. "the black cat crossed in front"
  15. "some hay fell off the truch"
  16. "martians landed in my cereal"
  17. "you can't spell dumbass without ass"
  18. "the truck went faster"
  19. "wheel fell off the right side"
  20. "the jester was entertaining the court\n"
  21. "a plane flew overhead"
  22. };
You need to put a comma at the end of each string otherwise all of these strings are concatenated together into sen[0] and the remaining entries in sen are uninitialized.
Oct 27 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: ali | last post by:
Hi, I'm trying to understand the reason for different output on the following codes Code1: #include <iostream.h> int main()
28
by: anonymous | last post by:
I have couple of questions related to array addresses. As they belong to the same block, I am putting them here in one single post. I hope nobody minds: char array; int address; Questions...
17
by: I.M. !Knuth | last post by:
Hi. I'm more-or-less a C newbie. I thought I had pointers under control until I started goofing around with this: ...
25
by: Sourav | last post by:
Suppose I have a code like this, #include <stdio.h> int *p; void foo(int); int main(void){ foo(3); printf("%p %d\n",p,*p);
10
by: Steve Pope | last post by:
The first of the following functions compiles, the second gives what I think is a spurious error: "cannot convert `const char' to `char *' in assignment". void foo(int m) { char *str; if (m...
8
by: mast2as | last post by:
I almost apologize to ask this question but I have been starting at this code for a bit of time and don't understand what's wrong with it. I am not arguing about the fact it's good or not coding,...
9
by: Peithon | last post by:
Hi, This is a very simple question but I couldn't find it in your FAQ. I'm using VC++ and compiling a C program, using the /TC flag. I've got a function for comparing two strings int...
9
by: J. Peng | last post by:
I just thought python's way of assigning value to a variable is really different to other language like C,perl. :) Below two ways (python and perl) are called "pass by reference", but they get...
3
by: Chris Saunders | last post by:
My C skills are rather meager so forgive me if I do not express my question clearly enough. Here is a struct that is declared in Windows: typedef struct _REPARSE_GUID_DATA_BUFFER { DWORD...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.