This program should capture a n number of strings, and show it backwards. I am required to make it with pointers, and using malloc(). But I cannot make my first function works. Please help me!!.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
int my_numbers(char *pointer,int numberlines)
{
int i, sizestring=0;
char linea[81];
for(i=0;i<numberlines;i++)
{
if(gets(linea)==0)
break;
sizestring = strlen(linea);
pointer=((char *)malloc(sizestring*(sizeof(char))));
}
return i;
}
void main()
{
char *pointer[100];
int numberlines=100;
int my_numbers(pointer,numberlines);
// int shownumbers();
// int freememory();
}
/*----------------*/
I have the following errors:
C:\Mis documentos\archivos C\pruebalunes.cpp(16) : error C2440: '=' : cannot convert from 'char *' to 'char'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Mis documentos\archivos C\pruebalunes.cpp(29) : error C2078: too many initializers
Error executing cl.exe.
pruebalunes.obj - 2 error(s), 0 warning(s)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
int my_numbers(char *pointer,int numberlines)
{
int i, sizestring=0;
char linea[81];
for(i=0;i<numberlines;i++)
{
if(gets(linea)==0)
break;
sizestring = strlen(linea);
pointer=((char *)malloc(sizestring*(sizeof(char))));
}
return i;
}
void main()
{
char *pointer[100];
int numberlines=100;
int my_numbers(pointer,numberlines);
// int shownumbers();
// int freememory();
}
/*----------------*/
I have the following errors:
C:\Mis documentos\archivos C\pruebalunes.cpp(16) : error C2440: '=' : cannot convert from 'char *' to 'char'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Mis documentos\archivos C\pruebalunes.cpp(29) : error C2078: too many initializers
Error executing cl.exe.
pruebalunes.obj - 2 error(s), 0 warning(s)