Re: [Dev-C++] Again with: gets,fgets,getline
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Lorenzo <co...@in...> - 2001-04-19 10:02:32
|
> <It seems that in my program is using memory addresses that shouldn't use
> because <it writes on some of my dynamic memory space.
You use the fgets but don't specific the file to use, you must open the file
to declare or use directly the standard input file (stdin).
> <I have read the "The GNU C Library" and while trying to use "getline"
instead
> of <"gets", it seems that getline is not in "stdio.h". In fact, searching
for
> it in <"stdio.h" like >Ctrl+F-> "getline", it doesn't found it.
I don't believe getline is the standard c function, is a member function of
iostream class library
try this:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
char pep[255],pitu[255],nitu[255],*pt,*ptg;
int i;
printf("Write something\n");
gets(pep);
printf("Write something more\n");
fgets(pitu, 255, stdin);
printf("Write something more again\n");
pt = (char *)malloc(256 * sizeof(char));
fgets(pt, 255, stdin);
system("PAUSE");
return 0;
}
|