473,386 Members | 1,799 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,386 software developers and data experts.

Main arguments

26
Basically I want to take a long string as an input whose size i don't know in C.
I want to do later functions on it.

Can anyone suggest any ways to do it.

Also I wanted to know can i do the same using main argument argv?????
Apr 5 '10 #1

✓ answered by newb16

google: arbitrary length string console input = http://anurag-priyam.blogspot.com/20...ry-length.html

4 1823
weaknessforcats
9,208 Expert Mod 8TB
Just opass your string as a char*. You don't need to know the length as you can call strlen() to find that out.

argv of main() is a pointer to an array of char*. So qall you need do is place your string on the command line. You increment argc when yo do this.

Any text on C will jave this information.
Apr 5 '10 #2
nk28
26
Thanxx for the reply but i do not want to know how to pass the string in the function......

What i want to know is how to take input of a string whose size has to be variable and i don't know it.............
Any other method than main(char *argv[])
Apr 5 '10 #3
newb16
687 512MB
google: arbitrary length string console input = http://anurag-priyam.blogspot.com/20...ry-length.html
Apr 6 '10 #4
weaknessforcats
9,208 Expert Mod 8TB
Why can't you use strlen()?

It doesn't matter whether it's an argument to main() or not sionce main() is just a function.

Expand|Select|Wrap|Line Numbers
  1. void func(char* str)
  2. {
  3.    unsigned int length = strlen(str);
  4. }
Apr 6 '10 #5

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

Similar topics

19
by: Steven T. Hatton | last post by:
The short sample program listed below has some features that I find to be bad style. In particular, they fail to communicate the connection between names used in this program and the location in...
7
by: qazmlp | last post by:
void func() { // Is it by anyway possible to read the value of the first command line parameter i.e. argv here ? } int main() { func() ; // No command line arguments are passed to func(). }
16
by: junky_fellow | last post by:
I was reading the various posts in this newsgroup, and found that main function should be declared as int main(void) // if no arguments are passed to main i wanted to know whats the purpose of...
5
by: Seong-Kook Shin | last post by:
Hi, I'm reading Steve's "C Programming FAQs" in book version, and have two question regarding to Q11.16 ... Also, a `return' from `main' cannot be expected to work if data local to main might be...
17
by: ern | last post by:
I want to pass arguments to the main( ) function of my C program. Currently, I'm using main(char * args) But when I try to print args, I get an unhandled exception error. Is there a better,...
6
by: rahulsinner | last post by:
Hello everyone, I have noticed everyone using "int main(void)".But doesnt the standard pronounces it as "int main(int argc,char *argv)".And if i don't specify arguments,why can't i simply put...
12
by: onkar | last post by:
sometimes main accepts int main() and sometimes int main(int argc,char** argv) and sometimes int main(int argc,char **argv,char** env) still the code complies properly How is this possible ???...
19
by: beliavsky | last post by:
I think I read a suggestion somewhere to wrap the code where a Python script starts in a main() function, so one has def main(): print "hi" main() instead of
15
by: arnuld | last post by:
i am not able to figure out the error: /* C++ Primer - 4/e * * exercise 7.16 * STATEMENT: * write a programme that accepts the arguments to main. print * the values passed to main. *...
2
by: significantBit | last post by:
n00b here. Just started learning C a couple of days ago. I'm using xcode alternatively with emacs. My question is in regards to the main function. Everytime I create a project (standard...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.