Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I have a problem with a program of counting strings and show them ... 1

Status
Not open for further replies.

a4524

Technical User
Oct 22, 2002
1
MX
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)
 
Try to change the:

Code:
int my_numbers(char *pointer,int numberlines)

to:

Code:
int my_numbers(char *pointer[],int numberlines)

And increase the pointer every time after it was allocated for memory.
 
Consider using realloc() also. In that case you can automatically increase the size of the pointer array, catering for as many lines as there is memory.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top