# print « Development « C File Q&A

Home
C File Q&A
 1 array 2 binary 3 delete 4 Development 5 directory 6 fgets 7 fopen 8 fprintf 9 fscanf 10 fwrite 11 header 12 include 13 input 14 LINE 15 linux 16 open 17 output 18 pointer 19 read 20 size 21 string 22 struct 23 Text 24 windows 25 write
 C File Q&A » Development » print

### 1. What is the most efficient way to print a file in C to stdout?    stackoverflow.com

I'm stuck on this. Currently I'm using:

FILE *a = fopen("sample.txt", "r");
int n;
while ((n = fgetc(a)) != EOF) {
putchar(n);
}

However this method seems to be a bit inefficient. Is there any ...

### 2. Print file (of any length) character by character in C    stackoverflow.com

Is there a way to print an entire file, character by character, without know it's length or worrying about how many lines it has? Right now I read a file and count ...

### 3. How to print hex numbers to a file?    stackoverflow.com

I am trying to store every hex value from 0000 to fffe into a file. How would I use fwrite or fprintf to place these values into a file? At the ...

### 4. Is there a program that automatically styles C files?    stackoverflow.com

I think the title is self-explanatory. Would be handy for large files with lots of style violations. Thanks guys :)

### 5. How to print both to stdout and file in C    stackoverflow.com

I read this topic, but his problem maybe different from mine Writing to both stdout & a file I want to write a fuction, that function need to print out to both ...

### 6. How do I get fgetc to print all the characters of a file inside of a loop    stackoverflow.com

I'm playing around with fgetc and was wondering how I would get my loop to print the line section once then print the first 16 characters. Here is my code:

int main(int argc, ...

### 7. Print Numbers to File in C?    stackoverflow.com

I'm a beginner to C but not too bad at programming all around. I'm writing a program in C that calculates the path of an object (x, y, and z coordinates) ...

### 8. GDB: What to do when you type "list" to see the code in C, but it prints to you "No source file for address __________"    stackoverflow.com

I'll try to simplify and make clear my other question here. I am basically trying to use gdb to see where myfile.c is segfaulting. However, I cannot directly examine myfile.c under ...

### 9. "print to file" icon is not displayed in Gtk Print File Window    stackoverflow.com

I am trying to print a Gtk Window using the print functionality provided by Gtk (e.g using api's like gtk_print_operation_run). The Gtk Print Window does n't show the "print to file" ...

### 10. program that prints the frequency of words in that file.    bytes.com

Use two arrays. Store the words in one array and the counts in the other. Read a word, search the array and if yu find it, say in element 10, then increment the count in element 10 of the other array. Now you have your words and the counts for those words. There are other solutions but for beginner's homework, the ...

### 12. Print .pcap file content on cosole/file that should be similar as Wire shark    bytes.com

If you can not find a utility to do this, Wireshark itself has a basic export to text file. If that wont do then you can access the data through the winpcap library or the file format is available here for you to decode the file yourself directly. A lot of the information displayed by Wireshare is not stored in the ...

### 15. Print bitmap file    bytes.com

I need to print a bitmap file in C under Windows. I'm a senior in college so please show me the respect I'm due. I don't want any of you jokers telling me that it can't be done because I know it can. Post the code here no later than Friday by noon, please. I'm counting on you guys to come ...

### 17. Printing files    bytes.com

Hey There, I'm learning C++ two different ways (in a class and through a book). right now i'm stuck (getting ahead) and i'm looking how to print a simple text file. problem being that on my computer i do not have a printer (as i'm making a program for a friend) and need to print a file which is the only ...

### 18. Trying to print a data file with words and numbers    cboard.cprogramming.com

Hi, I'm trying to create a menu for a program by printing a data file. This is what it looks like WELCOME TO MAZE-RUNNER DEMO THIS IS NOT YOUR MAZE RUNNER! This is a demo of possible Maze Runner Levels. The Levels are: Level 0: Drive the Mouse. You may use the a,s,d,w commands in the predefined visible maze. Level 1: ...

### 19. Printing to File using BST.    cboard.cprogramming.com

So, I just started Binary Search Trees in class this week, and this is part of a sample program to print student names to the stdout. For my program that I have to do I must print to a file, now I have tried a lot of times and the problem is that when I create a file in my "processStu" ...

### 20. printing from file problems    cboard.cprogramming.com

Code: void ld_apps() { FILE *fp; fp = fopen("G:/Uniwork/Semester2/ProceduralProgramming/Assignment/Appointment.txt", "rt"); if (fp == NULL) { printf("\nUnable to Open Input File\n"); exit(EXIT_FAILURE); } else { printf("File Open\n\n The Appointments are Shown Below\n\n"); } while ( !feof ( fp )) { Appointments++ ; printf("\n\nCurrent Number of Appointments: %d", Appointments); { fscanf(fp, "%s", PrAppArray[0].name); printf("\nName: %s", PrAppArray[0].name); fscanf(fp, "%s", PrAppArray[0].surname); printf("\nSurname: %s", PrAppArray[0].surname); fscanf(fp, ...

### 22. File not printing    cboard.cprogramming.com

Code: #include int testmkr(); main() { printf("Hello, would you like to make a test or take one.\n\ \npress '1' to make a test\nor '2' to take a test"); if(getch() == '1') { system("cls"); printf("Loading test maker..."); testmkr(); } } testmkr() { char title[200]; FILE *tfile = NULL; char buf[BUFSIZ]; char *titlefile; system("cls"); printf("...Loading complete"); system("cls"); puts("\n\nEnter title of test: "); ...

### 23. Print from file    cboard.cprogramming.com

I'm trying to get this code to print from a file data.txt which is in my c folder... it's compiling without errors or warnings, anyone see what could be wrong? As soon as I run the program prints nothing and closes (return 0). Doesn't even show me the menu I made. Code: /* My name is Jack Trocinski */ #include ...

### 27. Controlling variable values by printing on file    cboard.cprogramming.com

Hello to everybody. I have this simulation that implements some physical system. I get my results on a file using function fprintf. It-s a long Montecarlo simulation that gets one result in about half an hour. I have to collect much results and I write them on the same file. My problem is: the file seem to get an update only ...

### 28. printing "\n" every ten characters and also at the end of a file.    cboard.cprogramming.com

Hi guys! I am working on another assignment and I need your help. I am having trouble printing a \n every ten characters in the output file and also at the end of the output file. The reason you see all of those include files is because that this is a multi-file project. Code: #include #include #include "proto.h" #include ...

### 30. file printing problem!    cboard.cprogramming.com

Hi all, I'm writing information in a .bin and I want to print it back onto the screen. I think the writing works pretty fine, but when I try to print....weird characters appear...I have no compile errors and I don't know how to solve this. There are only 3 highscores. They get sorted by a qsort function, but I don't know ...

### 32. Print to file    cboard.cprogramming.com

#include #include FILE *fptr; main() { int age = 22; /* Simple variables to write */ float salary = 19670.50; fptr = fopen("C:\WINDOWS\DESKTOP\BT\MYDATA.TXT", "w"); /* Opens for output */ if (fptr == 0) { printf("An error occurred while opening the file.\n"); exit (1); } fprintf(fptr, "Here is some stuff:\n"); fprintf(fptr, "I am %d years old.\n", age); fprintf(fptr, "I make ...

### 33. Help with comparing two files and printing result to new file    cboard.cprogramming.com

I have four pre-interview problems to work through; this is likely the one that I will have to implement for tomorrow morning. This is seemingly an easy problem for seasoned C programmers, but albeit an elusive problem for me (I'm not verse in C by any standard).T My program must do the following: 1. read in data (non-formatted) from two text ...

### 34. how to print a file on the screen    cboard.cprogramming.com

I am having trouble bring information from a file into a structure and printing it out on the screen. How is that done? Here is the code I have that has the structure and the open statement. But not sure how to pull the data from the file and print it out.. Is that a plain printf statement? Code: #include ...

### 35. Homework HELP - Problem Printing to file    cboard.cprogramming.com

> This project is due at 11pm CST tonight Try www.cprog-tardis.com or www.cprog-miracles.com then. Quite what you expect anyone else to do about it with about 4 hours to go is beyond me. Maybe a course in basic time managment would be a good idea, because if you can't manage that, coding is not for you. > * You MUST use ...

### 36. printing picture files    cboard.cprogramming.com

well if you just can get the putpixel function working from some API you can some what print the BMP on the screen..(even console screen)... but for JPEG or anything else you will require API's that deal with that specific format.. The reason being that BMP is not compressed and you can pretty much directly read the RGB values where as ...

### 37. file to printer    cboard.cprogramming.com

The following peice of code should open the printerDevice (defined as LPT1), open my customers file and then the printer should print the contents. The code compiles and gets to the line containing "printf("File opened");" but then doesnt seem to do anything. Any ideas people?? Thanks Code: { FILE *printer = fopen(printerDevice, "w"); FILE *fp; if ((fp = fopen ("customers", "rb" ...

### 41. int varriable print to file    cboard.cprogramming.com

I wrote part of a bigger program and it has a few problems: 1. double prints the menu. 2. where the user has to print y to continue it prints the Q but automaticaly continues. I don't know why. Code: #include #include #include void New_Item(int); void main(){ char date[9]; FILE *it; FILE *his; char choice; char user_name[20]; printf("please ...

### 43. printing to a file    cboard.cprogramming.com

Okay... whoops... It wasn't _that_ simple but I had indeed just done a stupid mistake. Next question I have an input file containing 28 words (one per line). We are supposed to assume that the file is too big to fit into memory and only read in half the file at a time. I can now perfectly read in half the ...

### 45. New in c Prob with print record from file (linear probing and hash)    forums.devshed.com

hello i am new to forum and c. i have an exercise and i would like some help.( I am student) and i am having trouble and i cant save the records to file where i want so i can retrieve them. here is my code pls help me. i have to get the exercise ready until tomorrow morning. PLEASE w8 ...

### 46. Printing to file    forums.devshed.com

i get the problem now, i put the file pointer in the fscanf f part, and it compiles fine. The post about fgets however i am unsure about, i have never used #define, so not sure how to define the buffer size. fgets aside, if i am using fscanf i get a memory error when i am running the program, and ...

### 48. Send to print a file    forums.devshed.com

"r" means "read" (leer). Use it to input from a file. "w" means "write" (escribir). Use it to output to a file, as with fprintf(). Also, the '\' is an "escape character", which means that it marks the character that follows it as something special; eg, '\n' is newline, '\t' is tab. The escape sequence for the '\' is '\\'. So ...

### 49. I/O files allocating memory and print out charcters with while loops    forums.devshed.com

What this program does is allows you to enter the filename at the command prompt for the file that will be used to read information from, in additon to allowing you to enter the filename at the command prompt for a file that will write information to. THe only problem I am incountering is only reading in one line when there ...

### 50. Can not print file/Creates empty file    forums.devshed.com

Here's one problem, in get_info: scanf("%s", &filename); You need to remove the '&' from 'filename' as it's already a pointer. EDIT: It appears to run as intended, with that correction. If you plan to read and write random numbers, you'll want to open the file in binary mode rather than text mode (the default). In text mode on some systems, the ...

### 51. How to print exception handler messages to a file?    forums.devshed.com

Hello, I've got an ADT class written that contains exception handlers. What I need to do is print exception messages to an output file instead of to the screen. The only way I can think of to do this is to pass an ofstream reference to each function via main; however, the class currently has more than 30 functions, so I'm ...

### 52. sending bytes of a file to a printer    forums.devshed.com

I am writing a program for my fathers company that takes AutoCAD plot files and sends them to the printer of their choice. I created a sort of "Windows Explorer" look where they can choose files that then go into a queue and are printed. I'm new to C# but have a lot of experience in Java and C++ so the ...

### 53. File in-out not printing or creating out file    daniweb.com

#include #include #include char names[20][60]; int i, j; char name; void main(void) { FILE *in, *out; /* access to in.txt files */ printf("This program will read in names from the \nfile names.txt and print out to trans.txt.\n"); in = fopen("c:\\names.txt", "r"); out = fopen("c:\\trans.txt", "w"); for (i=0; i<20; i++) for(i=0;i<60;i++) names[i][j]=' '; for (i=0;i<20; i++) { fgets(&names[i][j], sizeof ...

### 54. printing a hardcopy from file from c.    daniweb.com

Good day, I am a freshmen student in need of some help. I have created an ATM program. This program has text files created for the withdraw transaction, deposit etc. It is like a database program for me. First of all, I would like to know how to compare strings and search within the text file the account number of a ...

### 56. printing to file and to stdout    daniweb.com

/* * open_file.c * trying to create a file. * */ #include #define FILE_NAME "C:\\progdir\\openf\\text.txt" void end_it() { printf("\nProgram ended. Press enter to exit: "); fflush(stdin); /* workes with this compiler */ getchar(); } int main(void) { FILE *file_ptr; /* structure pointer */ atexit(end_it); /* call end_it at anytime it exit */ file_ptr = fopen(FILE_NAME, "w"); if(file_ptr == NULL) { ...

### 57. Trouble with printing to a file    daniweb.com

#include #include #include #include #include #define MINMASS (0.0000515053396) #define pi (3.14159265) #define JUPVOL (6.98509E9 * 6.98509E9 * 6.98509E9 * (4.00/3.00) * pi) #define SOLM2G (1.98892E33) using namespace std; int main () { double j1, j2, j3, j4; ofstream file; file.open("big.in"); //open a file srand ( time(NULL) ); srand48(time(NULL)); j1 = drand48() * 0.013365; //mass needs to ...

### 58. Can anyone tell me how to print to alternate files?    daniweb.com

I have a program for a 5-way sort merge. I can get the program to read from the original file of 1,000,000 records and write them to 5 tempoary files (File0 thru File4). Then, I am suppose to close the temp files (Files 0 - 4) and open them as input, and open 5 more temp files (File 5 thru File ...