RBX
In the zone
I have a System Software lab test this Monday and we haven't been taught a thing. I tried something but am stuck at most basic things.
Here is my program, I need to find function signatures from a C program and add them to array. Working with Java for quite long has totally erased whatever C and C++ I knew from my mind.
First of all, I can't initialize an String array. This could be done with 'string' datatype but I want to do this with char arrays.
There also seems problem with strstr() && strstr().
also can't think for problem with line 17:a_file(str,ifstream::in);
Took help from:
Identification Of Function Signature - C And C++ | Dream.In.Code
ifstream::ifstream - C++ Reference
P.S. I kind of don't like pointers and have no idea of file handling.
Edit:
<merged>
Ok, got rid of some problems, but they still exist.
Here is my program, I need to find function signatures from a C program and add them to array. Working with Java for quite long has totally erased whatever C and C++ I knew from my mind.
Code:
/**
*Write a class for file handling, having functions to open/ read/ write/ close/ reset.
*/
#include<fstream>
#include<iostream>
#include<cstring>
using namespace std;
class FHandling {
ifstream a_file;
//char* ptr;
char func[][80];
char dt_type[5][7];
public: FHandling(char str[]) {
a_file(str,ifstream::in);
// *dt_type = {{"void"},{"int"},{"float"},{"double"},{"char"}};
dt_type = {"void","int","float","double","char"};
/*
dt_type[0]= "void";
dt_type[1]= "int";
dt_type[2]= "float";
dt_type[3]= "double";
dt_type[4]= "char";
*/
}
public: void search() {
int i=0;
char str[80];
while(!a_file.eof()) {
a_file.getline(str,80);
for(int j=0;j<5;j++) {
if(strstr(str,dt_type[j])) {
if(strstr(str,"(") && strstr(str,")") {
strcpy(func[i],str);
i++;
}
}
}
}
}
public: void show() {
for(int i=0;i<func.length;i++) {
cout<<func[i]<<"\n";
}
}
};
int main(void) {
FHandling f1("1_test.c");
f1.search();
f1.show();
return 0;
}
First of all, I can't initialize an String array. This could be done with 'string' datatype but I want to do this with char arrays.
There also seems problem with strstr() && strstr().
also can't think for problem with line 17:a_file(str,ifstream::in);
Took help from:
Identification Of Function Signature - C And C++ | Dream.In.Code
ifstream::ifstream - C++ Reference
P.S. I kind of don't like pointers and have no idea of file handling.
Edit:
<merged>
Ok, got rid of some problems, but they still exist.
Code:
#include<fstream>
#include<iostream>
#include<cstring>
using namespace std;
class FHandling {
ifstream a_file;
char func[][80];
char *dt_type[7];
public: FHandling(char str[]) {
char arr[5][7] = {"void","int","float","double","char"};
a_file(str);
for(int i=0;i<5;i++) {
dt_type[i] = arr[i];
}
}
public: void search() {
int i=0;
char str[80];
while(!a_file.eof()) {
a_file.getline(str,80);
for(int j=0;j<5;j++) {
if(strstr(str,dt_type[j]) != NULL) {
if(strstr(str,"(") != NULL && strstr(str,")") != NULL) {
strcpy(func[i],str);
i++;
}
}
}
}
}
public: void show() {
int size = sizeof(func)/sizeof(int);
for(int i=0;i<size;i++) {
cout<<func[i]<<"\n";
}
}
};
int main(void) {
FHandling f1("1_test.c");
f1.search();
f1.show();
return 0;
}
Last edited: