By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,795 Members | 1,235 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,795 IT Pros & Developers. It's quick & easy.

Bad array Declarator

P: 1
I have to create an array of 10 strings and put 10 quotes in each. I also have to create a while loop which I don't know where to start. I am having trouble compiling and I can't find any of this online.. Its driving me crazy - I am new to programming.

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. #include "stdafx.h"
  8. #include <string>
  9. string Quote;
  10. using namespace std;
  14. int main()
  15. {
  16.     // String Array
  17.     string Quote[9];
  18.     // Attach Values
  19.     Quote[0] = "Don't cry because it's over, smile because it happened.";
  20.     Quote[1] = "Be yourself; everyone else is already taken.";
  21.     Quote[2] = "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe.";
  22.     Quote[3] = "A room without books is like a body without a soul.";
  23.     Quote[4] = "You know you're in love when you can't fall asleep because reality is finally better than your dreams.";
  24.     Quote[5] = "You only live once, but if you do it right, once is enough.";
  25.     Quote[6] = "If you tell the truth, you don't have to remember anything.";
  26.     Quote[7] = "A friend is someone who knows all about you and still loves you.";
  27.     Quote[8] = "To live is the rarest thing in the world. Most people exist, that is all.";
  28.     Quote[9] = "Without music, life would be a mistake.";
  29.     return 0
  30. }
It says bad array decorator when it says string Quote[9]
Aug 12 '18 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 5K+
P: 5,397
It has been awhile since I've used C
I am most likely wrong; however, I am not sure that line 9 is needed...

I also think you need (most likely the error):
string Quote[10];

and I always used the typedef
typedef char * string;

Sorry I don't have a C compiler installed so I can't double check - WeaknessForCats will be along soon and will know the answer

Thank you for showing your work - normally we will not answer homework type problems unless the poster has shown that they've made an effort to solve the problem on their own first :-)
!Two Thumbs Up!
Aug 12 '18 #2

Expert Mod 5K+
P: 9,197
You created an array of 9.

That would be elements 0,1,2,3,4,5,6,7,8.
Aug 14 '18 #3

P: 115
As per the requiments, you can use a 2D character array. Quote[x][y] , here x is 10 but y needs to be mentioned (size of the maximum length quote).

Implementation for outputting:

Expand|Select|Wrap|Line Numbers
  1. for (i=0; i<x; i++){
  2.    printf("%s", Quote[i]);
  3. }
Aug 18 '18 #4

Post your reply

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