Yet another newbie problem. 
Author Message
 Yet another newbie problem.

I have a global variable "word" which is a pointer to a char* chosen at runtime
I want to have another global pointer /char [] "guessed" which will be the same
size as "word" but I need to be able to change individual characters in it.  Is
there an easy way to do this ?(I can't change the characters if its a pointer
and a char [] needs a constant value for the array size)

char *words[] = {"one","two","three"};
char *word
/* char *guessed;
...
srand(time(NULL));
int x = rand();
word = words[x%(sizeof words / sizeof words[0])];
/* Somehow get guessed to be same size as word but editable.

Thanks
Steve



Tue, 10 Apr 2001 03:00:00 GMT  
 Yet another newbie problem.

Quote:

> word = words[x%(sizeof words / sizeof words[0])];
> /* Somehow get guessed to be same size as word but editable.

word

char* junk = malloc(strlen(word)+1);
if (junk)
        strcpy(junk, word);
else
        printf("fresh out of memory\n");
.
.
.

free(junk);



Tue, 10 Apr 2001 03:00:00 GMT  
 Yet another newbie problem.
Thanks a lot. Exactly what I needed.
Steve
Quote:

>> word = words[x%(sizeof words / sizeof words[0])];
>> /* Somehow get guessed to be same size as word but editable.
>word

>char* junk = malloc(strlen(word)+1);
>if (junk)
>    strcpy(junk, word);
>else
>    printf("fresh out of memory\n");
>.
>.
>.

>free(junk);



Thu, 12 Apr 2001 02:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Yet Another Newbie Question/Keeping main() neat and tidy

2. Yet another newbie question

3. Yet another .net newbie question

4. ^yet^ another newbie question

5. Yet another CListCtrl() question from a newbie (sort question) on Dialog based project

6. yet another newbie question..

7. Newbie: Yet another Datagrid / ADO question

8. Yet Another Time Problem

9. Yet another var-arg problem...

10. Yet another small problem

11. Yet-another-realloc problem

12. DialogBar problem not solved yet.

 

 
Powered by phpBB® Forum Software