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

Pages: 1-

C PR0gramming..

Name: Anonymous 2012-05-26 3:39

Neeeed 'C' Help.

I need to read in input from the command line argument and open the text file ( 2nd arguement; nums1.txt in this case)
ie:  ./shitprogram nums1.txt

and so what would i be inputting here:
fopen("????","r");

I know that argv[1] = "nums1.txt" but how would i use this as a variable in fopen() ?

Name: Anonymous 2012-05-26 3:45

use this as a variable in fopen()
FILE* f = fopen(argv[1], "r");

If you read the manual page of fopen, you understand what the arguments and return value are.

Name: Anonymous 2012-05-26 4:00

ya kkan read input frum da kernal

Name: Anonymous 2012-05-26 4:00

five years on DA KERNEL will teach ya dat

Name: sage 2012-05-26 4:48

sage

Name: Anonymous 2012-05-26 5:56


#include <stdio.h>
int main(int argc, char** argv) {
    if(argc<2) {
        fprintf(stdio, "usage: %s filename\n", argv[0]);
    }
    int nig;
    FILE* fp = fopen(argv[1], "r");
    fscanf(fp, "%d", &nig);
    fclose(fp);
    return nig;
}

Name: Cudder !MhMRSATORI!FBeUS42x4uM+kgp 2012-05-26 7:11

Read K&R.

Name: Anonymous 2012-05-26 12:23

>>6
Use fread and not fscanf.

Name: Anonymous 2012-05-26 15:04

>>2
>single character variable name
I always use
FILE* stream;
myself.

Name: Anonymous 2012-05-26 15:17

>>9
I always use
FILE* reimu;
myself.

Name: Anonymous 2012-05-26 15:23

>>9
Your name is hardly any better, it isn't very descriptive, it's like FILE * file, of course it's a fucking file, but what is it used for?

Name: Anonymous 2012-05-26 19:08

>>11
It's a lot better. An 'f' could be anything, whereas a 'stream' is, well, a stream. What else would you call it?

Name: Anonymous 2012-05-26 19:50

>>12
not that dude, but if the FILE* is a local variable to a function that is initialized to a call to fopen, then I name the variable in accordance to what is stored in the file, or what will be written to the file. If the FILE* is just a parameter to some generic printing or reading function for a data type, then I'll either name the parameter input or output, depending on if data is being read or written to it.

this is all pedantic of course.

Name: Anonymous 2012-05-26 22:04

I use:
ALL_CAPS for preprocessor constants
some_name for local symbols
First_letter for symbols of function types
_some_name for global symbols
_, __, ___, ... for symbols that should not be used
__name_ for symbols that are deferred by a typedef
name_ for volatile symbols

as for the naming itself:
name_t for types
name_p for pointer types
name_c for types that are part of a bigger type
multiple_words for symbols with multiple words
CamelCase if the symbol is something that implements some OOP principles
camelCase if the symbol is a type of the above OOP implementation
i, j, k, l for generic cycles
ret for a local symbol to hold the return value
s, r, t for generic strings
file_name for most local symbols, the meaning is interesting on the local scope only

Name: Anonymous 2012-05-27 2:13

>>14
0/10

Name: Anonymous 2012-05-27 3:42

>>12
>It's a lot better. An 'f' could be anything, whereas a 'stream' is, well, a stream. What else would you call it?

Better is finp as in input file pointer.  A variable with trivial scope deserves a trivial name.

Name: Anonymous 2012-05-27 15:26

>>16
>finp
Abbreviations are not universally intuitive. I'm sure most people know what an ID is but "finp" is undescriptive. "stream" is still better. If you ever need to have an input and output stream (say you're writing a function that reads from one stream and writes to another), you can just call them "istream" and "ostream". Anyone reading the code immediately knows that both of them are streams, and can hence deduce that one is an input stream and the other an output stream.

>>13
That makes sense, so long as you name them intuitively.

Name: Anonymous 2012-05-27 17:51

FILE* dick; /* Output stream */
FILE* anus; /* Input stream */

Name: Anonymous 2012-05-27 22:29

>>17
Lets play a game of find the least intuitively named function in the C std lib.

I choose wcstombs()

Name: Anonymous 2012-05-28 0:45

>>19
I think wcspbrk() is worse. What does pbrk mean? It supposedly stands for "pointer break" but that's hardly more meaningful.

Name: Anonymous 2012-05-28 3:55

>>18
cat << /dev/dick >> /dev/anus

Name: Cudder !MhMRSATORI!FBeUS42x4uM+kgp 2012-05-28 4:49

>>19
wcs tombs - where wide character strings go to die.

Name: sage 2012-05-28 5:01

sage

Name: bampu pantsu 2012-05-29 5:11

bampu pantsu

Name: Anonymous 2013-08-31 19:28


The characters initially were too gimmicky to feel like actual characters, though they're starting to flesh out a little bit now.

Name: Anonymous 2013-08-31 20:58


 Anyone got the chart for latest Nogizaka's handshake event?

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