Hello, i am new in c programming it is just the second month i i deal with. I am really confusing about what i have to do with this exercise pls don't lough on me :( I hope for some help. That's what i have to do..

I have to modify an .ini file.
The user should enter a name which must be name1 or name2 else he get an error.
The user should enter the value of the name
the format is name1(or 2)=value
If the user use -D the input gets delete from ini
if the user dont enter both name and value gets an error
if the arguements allready exist replace them, if not add them
close file.


Thats what i have tried i have stuck soz again for this bad programme as i said its my second month :(

#include <iostream> 
#include <conio.h>
#include <stdio.h>
#include <string.h>

int delete= 0;


char parname[20];
char valname[20];
FILE *fdin;
char file[300];
char infile[60];


void main(int argc, char* argv[])
{if (argc!=3)
return;
strcpy(parname,argv[1]);
printf("Enter Parameter Name= %s \n",parname);
printf("Enter the value= %s \n",valname);
if ((fdin=fopen(infile,"r"))==NULL)
{ printf ("Open Error");
return;
}
for (n=0 ; fgets(file,sizeof(file),fdin); ++n)

for (i=2;i<argc;++i)
{ if(strcmp(argv[i],"-D")==0)
delete=-1;

Recommended Answers

All 5 Replies

I don't know where to start.

Are you using C or C++? You can't use <iostream> in C, but "delete" is a reserved word in C++. Neither language has <conio.h> (which is an archaic and non-standard header) or void main().

Your input problems are something else altogether, but you need to decide what language you're using first.

I don't know where to start.

Are you using C or C++? You can't use <iostream> in C, but "delete" is a reserved word in C++. Neither language has <conio.h> (which is an archaic and non-standard header) or void main().

Your input problems are something else altogether, but you need to decide what language you're using first.

I use c++ if u could provide some help i would appreciate thank you :)

I use c++ if u could provide some help i would appreciate thank you :)

Then why are you posting in the C forum? :icon_rolleyes:

We can't help you with C++ in the C forum.

Its ok for me the answer provided in C language or c++
I thought no many differences exist

Well, since you posted in the C forum, here's a C example of getting a filename from the user. It performs careful error checking, which may or may not be necessary for your purposes (but you're well advised to always do it).

#include <stdio.h>
#include <string.h>

int main(void) {
        char buf[80];
        size_t len;
        printf("Enter a filename: ");
        fflush(stdout);

        if (!fgets(buf, sizeof buf, stdin)) {
                fprintf(stderr, "EOF or input error\n");
                return -1;
        }

        len = strlen(buf);
        if (len + 1 < sizeof buf) { /* end of line reached */
                buf[len - 1] = '\0'; /* remove terminal \n */
        } else {
                fprintf(stderr, "Filename too long!\n");
                return -1;
        }

        printf("You entered '%s'\n", buf);
        return 0;
}

C++ would look quite different, with lots of std::cout and std::cin, I imagine.

Best of luck.

(Man page for fgets is available at http://www.opengroup.org/onlinepubs/009695399/functions/fgets.html . You may see scanf used to read interactive input, but don't do that.)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.