Hot answers tagged

2 votes
Accepted

how to read integers (separated with spaces) from a file line-wise?

Use a while loop to keep going through all of the characters (using fread) until end of file, and check if the char is a digit. If it is a digit, append it to your variable to hold the number and go ...
user avatar
  • 1,211
2 votes

Where are cs50.c / cs50.h?

The path name for the cs50.h header file is /usr/include/cs50.h. The path name for the cs50.c source file is /usr/src/cs50.c.
user avatar
2 votes

Where are cs50.c / cs50.h?

cs50.h goes here /**************************************************************************** * cs50.h * * version 1.1.6 * * Computer Science 50 * Glenn Holloway * David J. Malan * * ...
user avatar
  • 3,326
2 votes
Accepted

Directory structures

Do not type the prefix "~/ $ ", just start with mkdir. For example, here you can see the wrong way, followed by the right way to do this:
user avatar
  • 161
1 vote

How do I delete files?

To delete, navigate to the parent folder (aka directory) of what you want to delete in the command line (cd [folder name] to go down a level, cd .. to go up a level), then enter rm [filename], ...
user avatar
1 vote
Accepted

MY code works with a hardcoded string, but not a string object

This sequence = sequence_o.read doesn't execute the read function. It declares sequence as (basically) a copy of the read function. When a function does not take arguments (as with read), one must use ...
user avatar
1 vote
Accepted

What does a pointer to a file really represent?

A FILE pointer is a pointer to a struct. That struct contains numerous elements. (You'll learn about structs later, if you haven't already.) This particular struct is defined in stdio.h as follows: ...
user avatar
  • 64.2k
1 vote
Accepted

Code not working when saved inside bigger files

In a for loop we have three well differentiated parts, the initialization, the end of cycle condition and the counter that changes the variable in each pass of the cycle, these three parts are ...
user avatar
  • 5,172
1 vote

Files Won't Open In The Directory

Remember that you need to make a new file to write the images two. It looks like you successfully open card.raw, but all you do is name it in your for loop. You probably want to first read from your ...
user avatar
1 vote
Accepted

[PSET4][Recover] Why does FILE* img work but not FILE *img?

FILE* img and FILE *img are the same, you must have been observing some other effect. While I like grouping the * with the type, as the type of img is FILE*, there's also the argument that you might ...
user avatar
  • 20.7k
1 vote

How Do I Create A File

In the appliance, you could right-click the pset1 folder and select "New File", or you could change into the pset1 folder in your console, and write touch hello.c, touch by default sets the last-...
user avatar
  • 20.7k
1 vote

pset 5 Recover check if file open

Supposing that before the loop you declare the file where you will write data FILE *jpgfile = NULL; You can use if (jpgfile != NULL) to check if you have an already open file.
user avatar
  • 157

Only top scored, non community-wiki answers of a minimum length are eligible