filling an array with strings using gets()

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2004
Posts: 2
Reputation: Ginger is an unknown quantity at this point 
Solved Threads: 0
Ginger Ginger is offline Offline
Newbie Poster

filling an array with strings using gets()

 
0
  #1
Nov 1st, 2004
I'm trying to understand how to write a function to fill an array of strings using gets(array_name[i]),i being the row index. Ihave no clue how to even start this I have created a driver that declares a 2-D array that is a list of strings with one string per row. I don't know how to write this function however to fill the array up with strings. If anyone can just get me started I would really appreciate it, this is sadly all I have.


#include "driver.h"
void fill_it(char strings[][LENGTH], int* count) {
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,813
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 747
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: filling an array with strings using gets()

 
0
  #2
Nov 1st, 2004
Never use gets. It's impossible to make gets safe. All you need to do is match declarations:
  1. char strings[N][LENGTH];
  2.  
  3. ...
  4.  
  5. void f ( char strings[N][LENGTH], int size );
Then it's just a matter of counting from 0 to size - 1 and using fgets to fill strings[i] with a line. For example:
  1. int i;
  2.  
  3. for ( i = 0; i < size; i++ )
  4. fgets ( strings[i], LENGTH, stdin );
New members chased away this month: 3
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC