473,386 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

pointers and malloc and files

I'm trying to write a function that will read a file into dynamically allocated memory. Here's what I have so far.... the ReadString() Function is what I need help with. It's function prototype is in language.h and it's definition is in language.c . I'm pretty sure I have a mistake with my pointers so if someone could help me i'd appreciate it. This function needs to return arrayPamphlet[] with the contents of the text file, and lengthPtr as an integer with the number of characters in the array. Please don't rewrite out all the code perfectly for me, tell me what i'm doing wrong and how i might be able to fix it so i can actually understand this stuff.

Thanks!



/************************************************** ****************************
* File: proj3.c
*
*
************************************************** ****************************/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "language.h"

int numCharacters;
int numSpaces;
int numPunctuations;
int numDigits;
int numWords;
char filename[20];
char arrayPamphlet[]
char arrayLetters[26]
int lengthPtr;

int main (void)
{
PrintGreeting ();
ReadString(&filename, &lengthPtr);
Analyze ();
PrintResults();

return 0;
}





/************************************************** ****************************
* Function: ReadString
*
* This function reads the entire text file into dynamically allocated memory,
* returns a pointer to the text as it's return value and returns the length
* via the parameter lengthPtr by reference.
*
* Inputs: filename and lengthPtr
* Outputs: lengthPtr, arrayPamphlet
*
************************************************** ***************************/
char *ReadString (char *filename[], int *lengthPtr)
{
printf("\n\n Please enter a file name:");

scanf("%20s",filename[20]);

FILE * pFile;

pFile = fopen (*filename, "r");



return &arrayPamphlet;
}
Nov 5 '06 #1
1 1155
nevermind, i figured it out. Thanks!
Nov 5 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

388
by: maniac | last post by:
Hey guys, I'm new here, just a simple question. I'm learning to Program in C, and I was recommended a book called, "Mastering C Pointers", just asking if any of you have read it, and if it's...
3
by: Christian F | last post by:
Hi, I'm a C-newbie and I would like to know if I am doing something wrong in the code below. It is working, but I'm afraid it might not be correct because I don't really understand everything of...
8
by: Gerald | last post by:
I have a problem with an array of pointers. In a program I'm writing, I have to read a file, containing thousands of short lines. The content of another file will be compared against each line...
8
by: Grant Austin | last post by:
I'm implementing a hash table. I really think I'm doing everything acceptably but I'm still getting Seg Faults whenever I try and search the table and the symbol has not already been added to the...
20
by: fix | last post by:
Hi all, I feel unclear about what my code is doing, although it works but I am not sure if there is any possible bug, please help me to verify it. This is a trie node (just similar to tree nodes)...
7
by: Rano | last post by:
/* Hello, I've got some troubles with a stupid program... In fact, I just start with the C language and sometime I don't understand how I really have to use malloc. I've readden the FAQ...
6
by: paudirac | last post by:
Hi, I need to maintain N linked lists where N is determined at runtime. The linked lists are defined as follows, struct linked_list { int data; struct linked_list next; }
1
by: ketema | last post by:
Hello, I was wondering if someone could help me with a function I am trying to write. The purpose of the function is to read in text from a file in the following format: FIRSTNAME LASTNAME...
4
by: srini | last post by:
Hi I need to create two-dimensional array; number of rows and columns unknown at compile time. The idea is to read a file, print it if requested by user and to delete when the program quits. ...
39
by: Martin Jørgensen | last post by:
Hi, I'm relatively new with C-programming and even though I've read about pointers and arrays many times, it's a topic that is a little confusing to me - at least at this moment: ---- 1)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.