我想将函数值返回给main()
. 这是我的代码:
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <fstream>
using namespace std;
void Cryp(char *str){
int len = strlen(str);
int ch;
for(int i=0;i<len;i++){
ch = str[i];
ch = ~ch;
str[i]=ch;
}
}
char Deco(char *DESTINATION){
string line,str;
ifstream myfile(DESTINATION);
if (myfile.is_open())
{
while (getline (myfile,line))
{
string str(line);
str.erase (str.begin()+0, str.end()-9);
cout<<str; // THIS HAS TO BE RETURNED TO main()!-BUT HOW ??
}
myfile.close();
//remove(DESTINATION);
}
else cout << "Unable to open file";
return str.c_str();
}
int Dec(char *SOURCE, char *DESTINATION){
char Byte;
FILE *inFile = fopen(SOURCE,"rb");
FILE *outFile = fopen(DESTINATION,"wb");
if(inFile==NULL||outFile==NULL){
if(inFile) fclose(inFile);
if(outFile) fclose(outFile);
return 1;
}
else{
while(!feof(inFile)){
Byte = (char)fgetc(inFile);
char newString[256];
sprintf(newString, "%c", Byte);
Cryp(newString);
fputs(newString, outFile);
}
fclose(inFile);
Deco(DESTINATION);
}
return 0;
}
main()
{
Dec("/home/highlander/NetBeansProjects/simple/dist/Debug/GNU-Linux-x86/text.dat","/home/highlander/NetBeansProjects/simple/dist/Debug/GNU-Linux-x86/text_instant.dat");
cout<< Deco(char);
}
如何将str
函数中的值传递char Deco(char *DESTINATION)
给main()
.