| | |
filling an array with strings using gets()
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2004
Posts: 2
Reputation:
Solved Threads: 0
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) {
#include "driver.h"
void fill_it(char strings[][LENGTH], int* count) {
Never use gets. It's impossible to make gets safe. All you need to do is match declarations:
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:
C Syntax (Toggle Plain Text)
char strings[N][LENGTH]; ... void f ( char strings[N][LENGTH], int size );
C Syntax (Toggle Plain Text)
int i; for ( i = 0; i < size; i++ ) fgets ( strings[i], LENGTH, stdin );
New members chased away this month: 3
![]() |
Similar Threads
- how to read an array of strings in C++ (C++)
- 2d array of strings (C++)
- Declaring an array of strings in C++ (C++)
- Initializing an array of strings and printing it. (C++)
- Is there a way to tokenize an array of strings (C++)
Other Threads in the C Forum
- Previous Thread: Project idea needed using oracle as back end for the dbase and asp.net in the front..
- Next Thread: -$- Estimated Amount Of Money -$-
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays asterisks bash binarysearch calculate centimeter char convert copyanyfile copyimagefile copypdffile cprogramme createcopyoffile csyntax directory dynamic fflush file fork frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators infiniteloop initialization interest km lazy linked linkedlist linux linuxsegmentationfault list locate logical_drives match matrix meter microsoft motherboard multi mysql number open opendocumentformat opensource owf pattern pdf performance pointer pointers posix power problem probleminc program programming pyramidusingturboccodes read recursion recv repetition scanf scheduling scripting segmentationfault send shape socketprograming spoonfeeding stack standard string strings structures suggestions systemcall test testautomation unix user variable voidmain() wab win32api windows.h






