Can anyone help me how to write this programe in c langugage ? Write a program which can read an arbitrary file (in your program select a file, but we may select other files to test) and will output the number of bytes of the file.
-
-
Answer:
#include <stdio.h> #include <iostream.h> #include <Windows.h> void main() { WIN32_FIND_DATA wfd; HANDLE h; h=FindFirstFile("C:\Numbers.txt", &wfd); cout << wfd.nFileSizeHigh << " - " << wfd.nFileSizeLow << " - " << h << endl; getchar(); }
joreya at Answerbag.com Visit the source
Other answers
I won't do your homework for you especially on something this easy but to get you started you probably want to use stdlib.h use the argc and argv in main to pass a file name in so you don't hard code the name or just use standard input to read from so you can redirect the file name into your code. Use fopen() to open the file (if you choose to open a file rather than redirect from the already open stdin, see getchar()) and then a loop with a counter and use one of the getchar() variants to fetch from the file a byte at a time while incrementing the counter for size. Use a printf to output the size when you're done. That should make it pretty easy for you.
dichosa
Related Q & A:
- How to write a parser in C?Best solution by Stack Overflow
- How to write temporary files from temporary path to a temporary directory?Best solution by msdn.microsoft.com
- Can anyone help me do a website?Best solution by Yahoo! Answers
- Can anyone tell me how to select a University in Aus or NZ to study MA or MS or MBA in Communication?Best solution by Yahoo! Answers
- Can anyone help me create a screen name for myself?Best solution by nameideas.wordpress.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.