Solved

initialization of values

Posted on 2006-11-07
11
235 Views
Last Modified: 2010-04-15
how can i add 7 integers from the command line which are initialized to 9.

So for e.g. at the command line i create a file hello and then put 7(integers) and then 9(initialization value)

.\a.out hello 7 9


so all the values in the file are initialized to 9 when reading the file.
0
Comment
Question by:junaid_raja30
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
11 Comments
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 17892469

Hi junaid_raja30,

I'm not sure what you're asking.  Do you just want to write '7' and '9' into the file since they were passed on the command line?

0
 
LVL 84

Expert Comment

by:ozo
ID: 17893087
is this homework?
what part are you having difficulty with?
0
 

Author Comment

by:junaid_raja30
ID: 17893833
Yeah I want to right 7 and 9 into the file since they were passed on the command line.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 84

Expert Comment

by:ozo
ID: 17893909
you might want to do the write in a loop.
0
 

Author Comment

by:junaid_raja30
ID: 17894148
in what way? example?
0
 
LVL 24

Accepted Solution

by:
fridom earned 125 total points
ID: 17896266
fopen, fprintf, fclose. will surely help

Pseudo code

open the file fopen(fiel_name, "w+");

looping from
i = 0; i < atoi(argv[2])....
   fprintf("%s ", argv[3]);


fclose(file_handle)

That's all there is to do.

Regards
Friedrich
0
 
LVL 1

Expert Comment

by:nitinmathur5
ID: 17897203
1) Get the arguments from the command line (argc, argv).
2) Allocate memory for your variables (malloc or new).
3) Initialize the variables to the desired value

I hope you get the hint. or correct me if I am wrong
0
 
LVL 24

Expert Comment

by:fridom
ID: 18062733
sorry, what's the problem with my proposal?

Regards
Friedrich
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Suggested Courses

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question