Click here to Skip to main content
15,846,899 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to read and write to a BINARY file? Pin
dipuks29-Oct-09 13:46
dipuks29-Oct-09 13:46 
AnswerRe: How to read and write to a BINARY file? Pin
Member 419459329-Oct-09 14:05
Member 419459329-Oct-09 14:05 
AnswerRe: How to read and write to a BINARY file? Pin
enhzflep29-Oct-09 14:06
enhzflep29-Oct-09 14:06 
GeneralRe: How to read and write to a BINARY file? Pin
dipuks29-Oct-09 16:27
dipuks29-Oct-09 16:27 
GeneralRe: How to read and write to a BINARY file? Pin
enhzflep29-Oct-09 16:53
enhzflep29-Oct-09 16:53 
AnswerRe: How to read and write to a BINARY file? Pin
David Crow29-Oct-09 18:01
David Crow29-Oct-09 18:01 
AnswerRe: How to read and write to a BINARY file? Pin
Adam Roderick J29-Oct-09 18:58
Adam Roderick J29-Oct-09 18:58 
QuestionA General Problem Pin
WindowsVsLinux29-Oct-09 9:49
WindowsVsLinux29-Oct-09 9:49 
Hi,
I have the following program.
I want to use char array at the end of while loop so that after while loop if i use printf() statement it will be printed.I have already copy the directory in an char array.Actually i am something confusing at this time and cann't solve the problem.

#include<windows.h>
#include<string.h>
#include<stdio.h>

int main()
{
int length1,length2;
WIN32_FIND_DATA FindFileData;
HANDLE hFind = INVALID_HANDLE_VALUE;
char DirSpec[MAX_PATH + 1];
DWORD dwError;
char dirpath[MAX_PATH];

printf("Enter the path of directory: ");
gets(dirpath);

printf ("Target directory is %s\n",dirpath);
strncpy (DirSpec, dirpath, strlen(dirpath)+1);
strncat (DirSpec, "\\*", 3);

hFind = FindFirstFile(DirSpec, &FindFileData);

if (hFind == INVALID_HANDLE_VALUE)
{
printf ("Invalid file handle. Error is %u\n", GetLastError());
return (-1);
}
else
{

length1=sizeof(FindFileData.cFileName);
char firstdir[length1];
strcpy(firstdir,FindFileData.cFileName);
printf("First file name is %s\n",firstdir);
while (FindNextFile(hFind, &FindFileData) != 0)
{
length2=sizeof(FindFileData.cFileName);
char otherdir[length2];
strcpy(otherdir,FindFileData.cFileName);
printf("Other dir is:%s\n",otherdir);
}
/* ****************************************************
* here i want a char array *
* printf("All dir except first is:%s",array); *
* *
****************************************************/

dwError = GetLastError();
FindClose(hFind);
if (dwError != ERROR_NO_MORE_FILES)
{
printf ("FindNextFile error. Error is %u\n", dwError);
return (-1);
}
}
return (0);
}
I have commented the line where i want the char array.Actually i want this array outside while loop.
AnswerRe: A General Problem Pin
«_Superman_»29-Oct-09 10:04
professional«_Superman_»29-Oct-09 10:04 
GeneralRe: A General Problem Pin
WindowsVsLinux29-Oct-09 19:03
WindowsVsLinux29-Oct-09 19:03 
QuestionRe: A General Problem Pin
David Crow29-Oct-09 10:30
David Crow29-Oct-09 10:30 
AnswerRe: A General Problem Pin
WindowsVsLinux29-Oct-09 19:05
WindowsVsLinux29-Oct-09 19:05 
AnswerRe: A General Problem Pin
enhzflep29-Oct-09 10:36
enhzflep29-Oct-09 10:36 
GeneralRe: A General Problem Pin
WindowsVsLinux29-Oct-09 19:08
WindowsVsLinux29-Oct-09 19:08 
GeneralRe: A General Problem Pin
Adam Roderick J29-Oct-09 19:21
Adam Roderick J29-Oct-09 19:21 
Questionpointer and switch Pin
kbury29-Oct-09 9:18
kbury29-Oct-09 9:18 
AnswerRe: pointer and switch Pin
«_Superman_»29-Oct-09 9:21
professional«_Superman_»29-Oct-09 9:21 
GeneralRe: pointer and switch Pin
kbury29-Oct-09 9:24
kbury29-Oct-09 9:24 
AnswerRe: pointer and switch Pin
CPallini29-Oct-09 11:58
mveCPallini29-Oct-09 11:58 
GeneralRe: pointer and switch Pin
kbury30-Oct-09 3:31
kbury30-Oct-09 3:31 
GeneralRe: pointer and switch Pin
CPallini30-Oct-09 3:52
mveCPallini30-Oct-09 3:52 
GeneralRe: pointer and switch Pin
kbury30-Oct-09 10:37
kbury30-Oct-09 10:37 
GeneralRe: pointer and switch Pin
CPallini30-Oct-09 11:43
mveCPallini30-Oct-09 11:43 
GeneralRe: pointer and switch Pin
kbury30-Oct-09 11:57
kbury30-Oct-09 11:57 
GeneralRe: pointer and switch Pin
CPallini30-Oct-09 12:00
mveCPallini30-Oct-09 12:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.