So my goal is to create a console app using visual C++ lang which opens a file ( in my case it is a MIME file) and finds a certain string. In my case it sounds - Content-Disposition: attachment; filename="file.smth". And then the app shows the file.smth So here is what I have done. It has some problems that I am not able to find.When I run a console app It gets stuck at finding a filename.
#include "stdafx.h"
#include <stdlib.h>
#include <string.h>
bool ShowFile(char * FileName, char * Name)
{
FILE* file;
if (fopen_s(&file, FileName, "rt") != 0) { return false; }
while (!feof(file))
{
char AttName[100];
int a = sscanf_s("Content-Disposition: attachment; filename=\"%[^\"]\"", AttName,_countof(AttName));
Name = AttName;
}
fclose(file);
return true;
}
int main(int argc, char* argv[])
{
char FileName[100];
if (argc == 2) strcpy_s(FileName, _countof(FileName), argv[1]);
else {
printf("Source file name: "); gets_s(FileName, _countof(FileName));
}
char Name[100];
ShowFile(FileName, Name);
printf("%s \n", Name);
system("pause");
return 0;
}
Thank you for your attention!