thanks vart :)
Type: Posts; User: movl0x1
thanks vart :)
Thanks guys. But what I did was do a stat() on the first file (the one I want to copy) to
get its permissions (st_mode). Then I did an fopen() on the 2nd file (the one I want to create
and copy...
thanks laserlight.
I think I got it (maybe). :)
Hi. I see people declare functions as 'extern' in header (.h) files.
Is this what I should be doing?
someheader.h
/* someheader.h */
extern int func(int a, int b);
Why is this printing 0 instead of 5? Doesn't the modulus operator
result in the remainder after a division?
int main(void)
{
int c = 0;
int remainder = c % 5;
Sorry that was a typo:
I meant, and in my program had:
[code]
while(!(answer[0] == 'y' && answer[1] == '\n') &&
!(answer[0] == 'n' && answer[1] == '\n'));
Hi. I'm doing this loop:
char answer[3];
do {
printf("Enter (y/n): ");
fgets(answer, sizeof(answer), stdin);
Yeah, I forgot. printf() takes const char* argument for the %s conversion specifier and
isn't name[0] a const char* ptr (meaning that name[0] ALWAYS points to name array)?
So I'm casting name[0]...
Thanks, but how do I pass the st_mode (permissions) read by stat() to fopen?
with open I do:
open(filename, O_WRONLY | O_CREAT | O_TRUNC, fl.st_mode);
That creates a new file with...
Print out an ascii table with this code and it'll show all the ascii characters and their
values on stdout
#include <stdio.h>
#include <ctype.h>
int main(void)
{
Hello,
ex1
-----------------------------------
char *name[] = "brian";
printf("Hello %s.\n", name);
/* a very simple copy command for unix */
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <string.h>
int main(int argc, char *argv[])
{
struct stat flinfo; ...
Thanks everyone! :)
Hello. If I have the following struct
struct rec {
char name[20];
int age;
}p1;
char c = 0xff;
unsigned int a;
a = (unsigned int) c;
How come in the above cast "a" becomes ULONG_MAX or 0xffffffff? Since I am
casting to unsigned, shouldn't it cast to 0x000000ff, or...
Thanks brewbuck. I'll review the loop a little more and see what's going on, and then
I'll post the code if I'm still stuck. But yes, I'm using 3 different file pointers. Maybe I'm
just...
Yes. First learn assembly langauge and binary and hexadecimal. Then you'll know C. :)
Actually, download GNU C tutorial in pdf or whatever format. It's really a good tutorial.
Or yeah, Ivor...
Hi. Richard Stallman recommends to write functions like this:
int
function()
not like this:
int function();
Oh no, I know I can't use the same fp.
Thanks :)
I think I'll use fgets() :)
It's kinda difficult to explain.
1. I'm in a while() loop using fgetc() to read from one stream the name
of the filename my program will open. Say from this file:
----
filename1\n...
Hello fellow C lovers. I have a questions concerning reading from a stream.
Im reading filenames out of a file like this text file:
file.txt
-------------------
filename1\n
filename2\n...
Hi. Just wondering what the main differences between a file pointer and a file
descriptor are.
I know that a the FILE struct keeps info on the file stream in use. Correct?
But doesn't a file...
Actually, inside the computer this:
1111 1111 is -1 and
1111 1111 is 255 The way a computer differentiates is by
checking flags in the FLAG register.
Just because there's...
Hi. Alot of people say you shouldn't cast the returned pointer from malloc(),
but just make sure it's not NULL. Isn't malloc supposed to return type void?
Also, if you don't cast how will the...
thank you laserlight. Yes, maybe that was what I saw.