C :: File Opened In Main And Passing Pointer To A Function
Sep 14, 2013
I am getting a few compile errors for what might be a simple thing to do. I am opening a file in main, passing that pointer to a function and checking the contents of that file with a regex before I pass it on to build a BST. I am getting the following compile errors, what is wrong. Here are the errors:
Code:
gcc main.c fileCheck.c -o tree
main.c: In function `fileCheck':
main.c:19: error: syntax error before "FILE"
fileCheck.c: In function `fileCheck':
[Code] .....
Fatal error: Command failed for target `tree' Here is the two files and header that seem to be causing me the problems.
main.c
Code:
#include "main.h"
//#include "node.h"
int main(int argc, char *argv[])
FILE *fp;
if (argc > 2)
I am working on a project and decided to try something simple before I start adding items. I am calling a function from main and that function has a file pointer.
Here is my main.cpp
Code: #include <cstdio> #include <string> #include <iostream> #include "main.h" extern FILE *fp; using namespace std; int main(int argc, char *argv[])
My test file consists of several characters and digits. Nothing special and I at this point in time do not have any type of formatting that needs to be adhered to. I am simply wanting to read the file character by character and print it out. When I run the program, I get this symbol:
Code: If I use a printf statement, such as: Code: printf("%s ", nextChar);
This code is for a program that allows you to play a guessing game or arithmetic game and shows your total score from both as you go along. The program works fine the only problem I'm having is with the score. Is there a way to call the score value from the outside function into main?
So trying to pass the value of score from the outer function int guessGame() into the score print statement in choice 3 of the main function? Oh and the "17 -turn_count" was just part of the requirements of the assignment.
I have a a group of text files that are used as input into a program. Another very similar program needs the same data in a different input format. I am writing a program that will read in each line of data and parse it. I have successfully written the program in main() such that it will read until the end of file. However, I am trying to re-write the program such that the algorithm is in an external function and will read one line at a time and then pass all of the character strings to the main program. The program will not compile and I am positive it has to do with an incorrect use of arrays in passing the variable "token". I am attaching a copy of the main program and the function.
I'm trying to pass the value of an object created from a class file to a function outside of the "Int Main" function in the main.cpp file. I've successfully created the object, I just want to pass it to a void function but I'm getting the scope error below. I'm not sure how to correct. I'm not having much luck with research either (static variables?).
I am trying to make a information to pointer function but the problem is how/what number am i putting in for *a...
And can i get that information back to main? and is that right way to split the array in to ? because i have will 200 random number and I need to find the smallest and second smallest element in array.
two_smallest (print, size3,size3,size3,size3); } void two_smallest (int find_array[] , int size3, int *a, int *a2, int *b,int *b2) { for (int index = 0; index <= 100; index ++) { if (find_array[index] < find_array [0]) { find_array[0] = find_array [index]; *a = find_array[0];
I have int pointer called p and i want to calculate average.Since average involves using double or float so i am trying to convert this in the function averagetemp. It still gives me an error saying "cannot be converted"...
#include <iostream> using namespace std; int* createArray(int n); int lowesttemp(int *p,int f); int highesttemp(int *p,int f); double averagetemp(int *k,double f); void print(int *p,int lowest_temp,int highesttemp,int average_temp);
int Allocate(int, int *); main() { int *Pointer; int Elements = 25; // this works just fine - as expected. Pointer = (int *) malloc(Elements, sizeof(int)); // This DOES NOT - The value of Pointer never changes.....
int example (int [], int, *int,*int,*int,*int); int main () { My code will be here example (int array[], int size, &a,&b,&c,&d); // Like this??? I try it didnt work
I know if i will not use the pointer base class function "virtual double grossPay" will be called for both base class object and derived class object and when i will use pointer with reference to the object because base class function is virtual it will look for same function in derived class and if available it will execute it.
I am trying to wright a program that takes student grade data from a command line file, calculates a final grade, and copies the final grades to an output file. So far I have two functions, one that creates a student structure by allocating memory for it and returning its address, and one that should take that address and fill it with data from a line from the input file. My ultimate goal is to use a linked list to connect all the structs, but for now I just want to get the functions working. When I run what I have so far, I get an error C2440 (using visual 2010) that says "cannot convert from 'cStudent *', to 'cStudent', and points to the line where I call my fill function. How should structure pointers be passed?
I'm trying to pass the pointer of a dynamic array into a template function, but it keeps telling me there is no matching function to call because the parameters I'm passing in are wrong. how to make the function accept the pointer.
//main int main() { srand(unsigned(time(NULL))); int size; int *list; int *listCopy;
how I would copy a file's contents into a char buffer and copy it over to another file for files that can't be opened/read in notepad? (Example: a rar file or a .exe ) Not sure if that makes
Is there such thing as passing a winforms label by reference? For example, can I create a pointer label and pass the address to a function? I've looked online but couldn't find anything. Perhaps that's a sign?
The function should pass the square of the first input parameter and the cube of the second input parameter back to the calling routine. I thought I could use a recursion but its not going to work.
I'm new to C and encountered a weird problem. Here's the code:
int main(){ char name[]=""; readname(name) ; printf("The filename is: %s ",name); printf(name);
[Code] ....
I compile this with no problem, but gives "File could not be opened". the strcmp tells me name and "snazzyjazz.txt" are not equal. but when I print them I get the same output.
I have in the past written code for templated functions where one function argument can be either a function pointer or a Functor. Works pretty straightforward.
Now I am in a situation where I am actually trying to pass a function pointer as template argument to a class. Unfortunately this does not work, I can pass the Functor class but not the function pointer. Below code illustrates the issue:
The idea is to have the definition of the Record class simple and readable and have a maintainable way to add auto-conversion functions to the class. So the lines I commented out are the desirable way how I want my code to look. Unfortunately I could not come up with any way that was close to readable for solving this.