Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

C - String Array Help


  • Please log in to reply

#1
Joeturf

Joeturf

    Member

  • Member
  • PipPipPip
  • 158 posts
Hi G2G,

This is a program for school by the way, so no I am not making this lame program for personal uses haha :whistling: .

Anyway, the objective is to have a program that will let the user input 7 different Dates (in format 'January 7, 2007') and then redisplay the seven dates back to the screen in a list.

How can I make a 7-slot string array for dates, so that when my program retrieves each date it can store it in one of the slots (with a loop) and so on, so I don't have to make 7 different variables such as "Date1, date2, etc." ?

Edited by Joeturf, 18 January 2007 - 09:21 PM.

  • 0

Advertisements


#2
IO-error

IO-error

    Member

  • Member
  • PipPipPip
  • 276 posts
First things first:
Nobody here is allowed to do your homework for you.

I don't know for C language, but for VBS it's easily done this way:
Dim VarX(10)
Dim VarX(10, 10)
Dim VarX(10, 10, 10)

<explanation>
The first means you got 10 slots in your VarX
The second has (10×10) 100
The third has 1000 slots.
Although I'm not sure what the maximum amount of slots is, but it's probably not much.
</explanation>

Edited by IO-error, 19 January 2007 - 06:58 AM.

  • 0

#3
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 876 posts
as said in the last post - we won't do your homework

BUT, if you post your code, we can answer a question or 2
  • 0

#4
Joeturf

Joeturf

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 158 posts
Oops. Doing my homework is not what I meant, that is just a small part of what I need to know, Sorry if that sounded like that!

But my problem is that I want to make a string array. I can probably explain this better with an example.

Say I wanted to enter 5 of my friends names into a program. So I would enter the first name, then press enter, and the program would store it into a string. Then, I would enter a second name, then press enter, and the program would store that into a string.

Is there any way I can make an array of strings to hold that information? Or do I have no choice but to make 5 different strings such as "name1, name2, name3, etc."

I can do the program that way, so Im not asking for free homework doing haha, I am just trying to find an easier way to do it :whistling: .

Thanks for your help!
  • 0

#5
IO-error

IO-error

    Member

  • Member
  • PipPipPip
  • 276 posts
Name(1)
Name(2)
Name(3)

Get the point?
  • 0

#6
IO-error

IO-error

    Member

  • Member
  • PipPipPip
  • 276 posts
Ok, the tip:

Set Name(10) as String

Name(1) = Inputbox
Name(2) = Inputbox
Name(3)


So it's a bit different than have you expected, right?

Edited by IO-error, 24 January 2007 - 02:56 AM.

  • 0

#7
Ctrl_Alt_Del

Ctrl_Alt_Del

    Member

  • Member
  • PipPip
  • 74 posts
Hi Joe. Are you talking standard C or C++?


Unless something drastic has changed in C then it only has simple data types and string is not a simple data type so you would need an multi dimensional array of chars.

You can also use the multidimensional array or chars in C++ or you can use an array of strings.


To declare an array of chars in C is should be something like


char days[14][6];


This would allow the full format specified seven times since C is a zero based programming language. You may need to adjust the 15 to accomodate longer months is Jan isn't the longest.

You'll need to access each character in an inner loop and each day in the outer loop.


Does all of that make sense?


Google "C Arrays" for more info and you can also check here.
http://publications....er5/arrays.html

Edited by Ctrl_Alt_Del, 24 January 2007 - 03:23 PM.

  • 0






Similar Topics

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP