473,322 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

dynamic string lenght

1
I have to read input from the keyboard and save it as a string (but in C strings are acctually character arrays or something?) that I am going to manipulate later. That wouldn`t be a problem except there must be no artifical limit to the string lenght. It has to fit into the array size no matter if it is a million letters long so I can`t just make room for it with a char word[100]; declaration like I would usssually.

So how do I solve this and make the array be the size of whatever the input lenght is? I`m guessing it has to be something with malloc function, but I have no idea how exactly. Neither logic nor syntax wise.
Apr 8 '07 #1
2 2172
weaknessforcats
9,208 Expert Mod 8TB
Everything has a limit and this case is not different.

Just set a minimum length. Get that many characters from the keyboard. Allocate memory for those characters and copy from your buffer to your allocation. If you did not encounter the enter key, then accept the minimum legnth characters again. Attach the second fetch to the first (good place ofr a function here). Keep fetching until you have gotten all the characters.
Apr 8 '07 #2
Ok, just say:

Expand|Select|Wrap|Line Numbers
  1. char *word[100];
  2.  
This means that you will have an array of 100 character arrays with no specific defined size of each element.
Apr 9 '07 #3

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

Similar topics

14
by: Spare Change | last post by:
I am told that I can have a dynamic or static string array. So if I declare string dynamic; How do I add elements to dynamic and resize it ?
4
by: Robert | last post by:
Hi, How can i resize an array of strings to add more? This is an example i just downloaded from a website: char *cpArray; int i; for (i = 0; i < 10; i++) cpArray = (char *)malloc(20 *...
1
by: smeagol | last post by:
I have a varchar 255 field in the Sql. When i get the data with (string)myReader; it's trimed ie( SQL : "qwerty " (Lenght 255) c# :...
2
by: pyrexia | last post by:
Greets all. I'm attempting to write an app that will be used as a 'control/launcher' application for other apps. For the sake of argument let's say the app is launched from a command line: ...
2
by: DJAudette | last post by:
Hello I am using vba in excel. I am trying to do the following seeing instr is not working I am writing my own program. Just I am having an issue with this dynamic array. here is a clip of...
8
by: cdolphin88 | last post by:
Hi, I'm reading from a .dat file and I want to know the length of the string . I' using the stringRef.length () but the compiler said there was an error `stringRef' undeclared (first use...
0
by: Fareast Adam | last post by:
Hi all, anybody know how to create dynamic array random password (lenght and no of password)? The program request an user to insert no of password AND lenght of password to be generate. After that,...
4
by: javaalien | last post by:
Could someone please help me how to count lenght string in a file? I have input file like this: 1039387845 35368535615253 695 .... Kindly pls assist me how to count the lenght. Thank you in...
1
by: Barok | last post by:
hello peeps, i just startet to coding in c, and dont have a big background. now i have a problem witch i dont understand. i hope you guys can help me out here. the problem is malloc. i try...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.