All pastes #571825 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-06-17 10:29 UTC
rendered paste body
void GetWordLengths (FILE *p,char **a,int amountOfWords)
{
	int i,length=0;
	char c=fgetc(p);
	for (i=0;i<amountOfWords;i++)
	{
		if (c!='\n' && c!=EOF)
			length++;
		else
		{
			length++; /*the charecter '\0' is a place in the word's array*/
			if ((a[i]=(char *) malloc (length*sizeof(char)))==NULL)
			{
				printf ("allocataion failed\n");
				exit (1);
			}
			length=0;
		}
		c=fgetc(p);
	}
}
void GetWords (FILE *p,char **a)
{
	int i=0,j=0;
	char c=fgetc(p);
	while (c!=EOF)
	{
		if (c!='\n')
		{
			/*a[i][j]=c;*/
			j++;
		}
		else
		{
			j=0;
			i++;
		}
		c=fgetc(p);
	}
	return;
}