Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

File/File Size list - C

Name: Anonymous 2011-11-22 7:02

Was wondering if any C guru's knew where the hell im going wrong with my code, I just want to list file names and file sizes of files in a directory, file sizes seem to be printing as addresses. Learning C is hard ;(

Should be easy!

http://pastebin.com/Y6ruNEum

Name: Anonymous 2011-11-22 7:27

stat seems to be coming back with an error (my code was borked, printing only when it errored.. which was all the time).

a pineapple for the person that tells me why!

Name: Anonymous 2011-11-22 7:43

Name: Anonymous 2011-11-22 7:49

amazing, but I cant use ls because its going to expand further than this :(

Name: Anonymous 2011-11-22 8:05

what is this retarded shit. if you exec, you don't have a process anymore to do anything,

Name: Anonymous 2011-11-22 8:31

>>1
stat returns 0 on success. Also, readdir returns "." and ".." which you should check for and ignore. The dirent structure has a d_type member which can be used to determine if an entry is a file or directory, which you should check and only call opendir on actual directories.

Also, your code only goes 2 levels deep, you should implement a recursive function to properly recurse into the file system directory tree.

Name: Anonymous 2011-11-22 8:40

OP here, thanks a lot, been annoyed at trying to figure out how I can remove .. and .

Name: Anonymous 2011-11-22 8:42

>>7

if (!strcmp(directory->d_name, ".") || !strcmp(directory->d_name, "..")) {
    continue;
}

Name: Anonymous 2011-11-22 8:45


char fnames[30];
...
... sizeof fnames[0] ...

Not this shit again.

Name: Anonymous 2011-11-22 8:47


char fnames[30];
int fnames_size = sizeof fnames / sizeof fnames[0];

wow.

Name: Anonymous 2011-11-23 13:05

Take note of my repeating digits.

Name: Anonymous 2011-11-23 13:16

>>11
Take note of my anus.

Name: Anonymous 2011-11-23 13:44

>>8
Or you invert the condition and put your code to do stuff with the dirent inside it, like so:

if (strcmp(directory->d_name, ".") && strcmp(directory->d_name, "..")) {
    /* do stuff with it */
}

Name: Anonymous 2011-11-23 13:46

Coercing the return value of strcmp to boolean considered obfuscated.

Name: Anonymous 2011-11-23 14:51

>>14
Integers are booleans in C, although I agree in this case, as strcmp returns only non-zero when the string aren't equal.

Name: Anonymous 2011-11-23 16:04

>>15

Integers are booleans in C

No they aren't you fucking dumb uneducated nigger. Maybe you should actually read something like K & R instead of say, running your mouth here. Now fuck off you idiot.

Name: Anonymous 2011-11-23 16:06

>>16
Yeah, they are, they are interpreted as true when they are non-zero and false when they are zero.

You can thank me later for educating you.

Name: Anonymous 2011-11-23 16:07

>>15

Also dumb nigger boy, if you had ever worked any kind of actual programming job, you would have also realized you could get pretty close to emulating booleans in c buy using some semi-conformant asserts in your code.

Name: Anonymous 2011-11-23 16:08

>>17
No they aren't you fucking nigger. I can actually cite several lines of working C code where this would break down. Again you're stupid. And again, you have no possible future as a computer programmer.

Now shut the fuck up and read the ANSI/ISO C standard.

Name: Anonymous 2011-11-23 16:10

>>17
Also, I know what I'm talking about because, unlike you

a)I hold a master's degree in computer science.
b)I work as a computer programmer.
c)I used to be an work on the C89 committee.

Name: Anonymous 2011-11-23 16:16

>>20
Explains why C is so shitty you asshole.

Name: Anonymous 2011-11-23 16:19

>>21
I'm not the idiot that is saying shit like..

Yeah, they are, they are interpreted as true when they are non-zero and false when they are zero.

Also, in if would have made it beyond high school algebra, you would have also realized that there are no such thing as "integers" in C. But of course I don't expect a mental midget to know such a subtle, but important difference.

Name: Anonymous 2011-11-23 16:24

>>18-20,22
Do you have trouble reading?
Read >>17 again, you may thank me later for helping you with your C programming.

Name: kodak_gallery_programmer !!VIk1pgCZf9P/QBQ 2011-11-23 16:26

>>23
Stop projecting. I'm not the faggot that is saying shit like....

Yeah, they are, they are interpreted as true when they are non-zero and false when they are zero.

C doesn't support such crap. This is evident is C89 and C99 you fucking dumb jew. Now fuck off and scrub another toilet.

BTW, I'm not granting you the first technical interview.

Name: Anonymous 2011-11-23 16:28

>>20
I used to be an work on the C89 committee
Really, what is your name?

Name: Anonymous 2011-11-23 16:31

>>20
>>19
>>18
>For each of the signed integer types, there is a corresponding (but different) unsigned
integer type (designated with the keyword unsigned) that uses the same amount of
storage (including sign information) and has the same alignment requirements. The type
_Bool and the unsigned integer types that correspond to the standard signed integer
types are the standard unsigned integer types. The unsigned integer types that
correspond to the extended signed integer types are the extended unsigned integer types.
The standard and extended unsigned integer types are collectively called unsigned integer
types.30)

>When any scalar value is converted to _Bool, the result is 0 if the value compares equal
to 0; otherwise, the result is 1.

Also, true and false are macros that expand to 1 and 0 respectively. Even though it has its own type, it's still an integer, faggot.

Name: Anonymous 2011-11-23 16:32

>>24
Okay, since you are clearly struggling with your C programming I will help you. I'm going to set up a minimal test program which you can try to compile and run

#include <stdio.h>

int main (void) {
  int a = 10;
  int b = 0;

  if (a)
    puts("This test hits!");

  if (b)
    puts("This test doesn't hit :-(");

  return 0;
}


Your next assignment is to compile and run this and tell me the output, if you have any trouble doing so you can post it here.

Also feel free to thank me later for helping you, although I'm happy to help I like being appreciated.

Name: Anonymous 2011-11-23 16:33

>>27
I will not help you set up your environment correctly though, that you have to do by yourself.

Name: kodak_gallery_programmer !!VIk1pgCZf9P/QBQ 2011-11-23 16:38

>>26
And where does it say this implies true and false you dumbass? Again, I can cite several lines of code where the whole 1/0 being uses as true/fals breaks down.

Name: Anonymous 2011-11-23 16:38

Okay, I will help you since you seem to be struggling with this, the output should be (don't look if you think you will be able to do this by yourself!)

This test hits!

Name: Anonymous 2011-11-23 16:39

>>29
Well first of all, 1/0 is not an integer.

You can ask any questions if you are confused in this thread, I am very experienced in teaching others.

Name: Anonymous 2011-11-23 16:42

>>29
page 253

7.16 Boolean type and values <stdbool.h>
1 The header <stdbool.h> defines four macros.
2 The macro
bool
expands to _Bool.
3
The remaining three macros are suitable for use in #if preprocessing directives. They
are
true
which expands to the integer constant 1,
false
which expands to the integer constant 0, and
_ _bool_true_false_are_defined
which expands to the integer constant 1.
4
Notwithstanding the provisions of 7.1.3, a program may undefine and perhaps then
redefine the macros bool, true, and false.216)

I understand you probably don't have access to this standard. You can find equivalent information on manpage of stdbool.h.

Name: kodak_gallery_programmer !!VIk1pgCZf9P/QBQ 2011-11-23 16:43

>>31
Well first of all, 1/0 is not an integer.

Well not shit walmart boy.

You can ask any questions if you are confused in this thread, I am very experienced in teaching others

Again, you have no clue as to what is going on. Have you ever writen C code for a living? Have you ever actually read one of the various standards? I bet the answer to both questions is no.

It seems like the extent of your knowledge is "googling". Again, you are stupid. Again, you have no possible future as a computer programmer. And again, I refuse to grant you the first interview for any kind of programming job here at Kodak.

Name: Anonymous 2011-11-23 16:43

>>32
Relax now, I don't think he is ready for pre-processor directives or header files.

Believe me I have ten years of experience teaching others.

Name: Anonymous 2011-11-23 16:44

>>29
Oh, and, please do cite the code where it breaks down. I'm very interested indeed.

Name: kodak_gallery_programmer !!VIk1pgCZf9P/QBQ 2011-11-23 16:44

>>32
Like I just told the other minimum wage faggot, I can cite several lines of C code where this analogy breaks down.

Name: Anonymous 2011-11-23 16:47

>>33
Have you tried to compile the program and run it yet? I think it would be a positive learning experience for you.

I refuse to grant you ...
That's all right, I don't like photography anyways :-)

Name: Anonymous 2011-11-23 16:49

>>35
Now who is teaching who you nigger? With that, try the following..

a = 2;
b = 3;
if (a) printf(" a is true\n")
if (b) printf("b is true\n");
if (a == b) printf("a == b\n"); else printf("a != b\n");


In C, you should not test for "true"

Name: Anonymous 2011-11-23 16:51

>>38
I will explain to you why that happens.

When you do the comparison a == b you think of the integers (a and b) as integers, not booleans.

Still, if you have any questions, feel free to ask, I will have answers for you :-)

Name: kodak_gallery_programmer !!VIk1pgCZf9P/QBQ 2011-11-23 16:52

>>37
So? You are too stupid to handle anything beyonnd "googling" shit. Even if I was back and International Papers, I still wouldn't have granted you the first technical interview.

Name: Anonymous 2011-11-23 16:54

>>39

When you do the comparison a == b you think of the integers (a and b) as integers, not booleans.


Again, there are no such thing as "integers" in C. Also what happens if a==b is used in an if/else clause? Clearly if/else either evaluates to valid or not valid. Again, for like the 4th time, you're a stupid fucker with no possible future as a computer programmer.

Name: Anonymous 2011-11-23 16:56

>>38
So what? In first two ifs one kind of integer type is being coerced to another. It behaves exactly as it should and it nicely illustrates that Booleans are integers.

Name: Anonymous 2011-11-23 16:56

>>40
You seem to have issues with English, if you are not from an English speaking country that is not an excuse(!).

It is "beyond" not "beyonnd", also the sentence "Even if I was back and International Papers, ..." doesn't make any sense.

I recommend that you work on your English and your C programming, and you would be successful.

Also you seem to be very ungrateful, I have done nothing but help you yet you seem to be angry at me for some reason. Is this how you would behave at home with your mother? I don't think so.

Name: Anonymous 2011-11-23 16:58

>>43
Stop projecting and go scrub another toilet you fucking nowhere bitch.

Name: Anonymous 2011-11-23 16:59

WHBTC

Name: Anonymous 2011-11-23 17:00

>>42
There is no implict conversion going on. And the fact that you thing there might be not only makes you stupid, but also mentally retard. Again, you're stupid.

Name: Anonymous 2011-11-23 17:01

>>45
Internet slang? Oh geeze. Go kill yourself.

Name: Anonymous 2011-11-23 17:02

>>46
Jesus fuck. You are a fucking retard.

IHBT

Name: Anonymous 2011-11-23 17:06

>>48
No you haven't you dumbass jew. Tell us all what you do for living. Have you ever worked on any of the C committees? How many hundreds of thousands of people use your C code? Did you even make it beyond high school?

The fact that you won't answer any of this implies that your a fucking high school graduate that works some hourly job. Now go scrub my office you bitch before I write you up.

Name: Anonymous 2011-11-23 17:06

>>48
Now, now, there is no room in the classroom for such talk. He may not be as gifted as you but that is no way of talking to a fellow classmate.

And before you say that this is not a classroom and that he is not your classmate keep this in mind, life is a learning experience.

Name: Anonymous 2011-11-23 17:09

>>49
Do you have an erection right now? I always get one when I wear panties and I picture you now in panties.

Name: Anonymous 2011-11-23 17:29

>>51
Do you picture him wearing panties or do you picture him in arbitrary state while you wear panties?
I need to know, this is important!

Name: Anonymous 2011-11-23 18:26

>>52
Roll around in the ambiguity. Soak it in.

Name: Anonymous 2011-11-23 18:37

>>53
nooooooooooooooooooooooo

Name: Anonymous 2011-11-23 19:43

In case anyone's interested, there's a basic implementation of this described in "The C Programming Language" book.

Somehow I think Kernighan and Ritchie can write a decent example...

Name: Anonymous 2011-11-23 23:29

Yet another thread ruined by the idiot troll.

Just ignore him, guys.

Name: Anonymous 2011-11-24 7:12

not anime

Don't change these.
Name: Email:
Entire Thread Thread List