•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 429,994 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,396 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 709 | Replies: 13 | Solved
![]() |
i just noticed you have defined your "sentence" array as pointer to "const char"... the "const" means that you can't change it. you'll want to define it as type "char"
a separate issue is that you have it as a pointer... if you're going to copy a string into it (and you will need to), then you need to lose the pointer and declare it as an array of strings.
now you'll have to use "strcpy" to copy the word into the "sentence" array... you cant use assignment operators (= signs) to copy strings.
sorry i didnt see this earlier.
.
a separate issue is that you have it as a pointer... if you're going to copy a string into it (and you will need to), then you need to lose the pointer and declare it as an array of strings.
char sentence[7][35]; (i dont think you need 35 characters per word, since each of the "sentence" arrays is just a copied word... but thats a trivial point.now you'll have to use "strcpy" to copy the word into the "sentence" array... you cant use assignment operators (= signs) to copy strings.
sorry i didnt see this earlier.

.
Last edited by jephthah : Jun 10th, 2008 at 2:04 am.
Why so serious?
since you tried so hard, and i ran you around in circles, here's the fix:
c Syntax (Toggle Plain Text)
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <ctype.h> int main(void) { const char *article[ 5 ] = {"the", "a", "one", "some", "any" }; const char *noun[ 5 ] = { "boy", "girl", "dog", "town", "car" }; const char *verb[ 5 ] = { "drove", "jumped", "ran", "walked", "skipped" }; const char *preposition [ 5 ] = { "to", "from", "over", "under", "on" }; char sentence[7][35] = {0}; int a=0, b=0, c=0, d=0, e=0, f=0; int counter=0; srand(time(NULL)); for (counter=1; counter <= 20; counter++) { a = rand() % 5; /*random numbers for each array of words */ b = rand() % 5; c = rand() % 5; d = rand() % 5; e = rand() % 5; f = rand() % 5; strcpy(sentence[1], article[a]); strcpy(sentence[2], noun[b]); strcpy(sentence[3], verb[c]); strcpy(sentence[4], preposition[d]); strcpy(sentence[5], article[e]); strcpy(sentence[6], noun[f]); sentence[1][0] = toupper(sentence[1][0]); printf("%s %s %s %s %s %s.\n", sentence[1], sentence[2],sentence[3],sentence[4], sentence[5],sentence[6]); } printf("\n"); system("PAUSE"); return 0; }
Why so serious?
![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the C Forum
- Previous Thread: General C question (variables)
- Next Thread: Regarding Float Code



Linear Mode