Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
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
  • 875 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

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP