[beginner] C reading lines, and numbers
1
Name:
Anonymous
2009-08-29 8:56
I have a file in which ever line of text is terminated with a number. I'd like to extract the text and the number to variables, how do I do that?
2
Name:
Anonymous
2009-08-29 8:58
Go to /pr/. Ask there.
3
Name:
Anonymous
2009-08-29 9:00
You should write a program to do it.
4
Name:
Anonymous
2009-08-29 9:04
>>3
you know, I'd have never thought of that.
5
Name:
Anonymous
2009-08-29 9:05
if(c <= '9' && c >= '0')
that's all i'm saying.
go to /pr/
6
Name:
Anonymous
2009-08-29 9:09
awk(1)
7
Name:
Anonymous
2009-08-29 9:10
use regexen
8
Name:
Anonymous
2009-08-29 9:19
Two lines in Python.
9
Name:
Anonymous
2009-08-29 9:23
10
Name:
Anonymous
2009-08-29 9:26
11
Name:
Anonymous
2009-08-29 9:29
No lines in HASKAL.
12
Name:
Anonymous
2009-08-29 9:29
Five screenfuls in Java.
13
Name:
Anonymous
2009-08-29 9:31
>>11
Actually you could do it in a single one but it would be
imaginary .
14
Name:
Anonymous
2009-08-29 9:38
>>13
An imaginary line in a fictional language? Who'da thunk it?
15
Name:
Anonymous
2009-08-29 9:55
>>14
There are no fictional languages.
16
Name:
Anonymous
2009-08-29 10:13
>>15
ada started from a fiction
17
Name:
Anonymous
2009-08-29 10:23
>>15
Haskell is the world's leading fictional programming language, everyone know's that
18
Name:
Anonymous
2009-08-29 10:23
>>16
The fiction of a woman who knew math?
19
Name:
Anonymous
2009-08-29 13:29
int doit() {
char buf[64];
int n = 0;
size_t i, x = 1;
if(fgets(buf, 64, stdin)) {
i = strlen(buf);
while(i && isdigit((unsigned char)buf[--i]))
n += (buf[i] - '0') * x, x *= 10;
if(buf[i] == '-') return -n;
return n;
}
}
20
Name:
Anonymous
2009-08-29 13:31
>>19
notice the newline that usually will be there with
fgets (unless the user types something like
foo bar-123^D), is not trimmed, on purpose. If you desire such functionality implement it yourself.
21
Name:
TimeTravelingAdaLovelace
2009-08-29 13:32
22
Name:
Anonymous
2009-08-29 13:40
>>20
notice the enlightment that usually will be there with
SICP (unless the wizard cast something like
(macrolet ((spell () `(,@(loop (princ '|SUSSMAN |)))) (spell))), is not permanent, on purpose. If you desire such functionality implement it yourself.
23
Name:
Anonymous
2009-08-29 13:41
>>19
You know, variable names can be longer than three characters, even in C.
24
Name:
Anonymous
2009-08-29 13:48
>>23
Yes I'm aware. In fact, I even took the privilege to name a four character function in that program, `doit', admittedly elusive to your punny excuse-for-a-brain.
25
Name:
Anonymous
2009-08-29 13:50
int num = 0;
char c;
while((c = getchar()) >= '0' && c <= '9'){
num += (c - '0') * 10;
}
dus dis wurk?
to sav cher raray is easy. u dun ned me to do dat fur u
26
Name:
Anonymous
2009-08-29 14:01
>>25
Well if 123 means 321, sure, it dus wurk.
27
Name:
Anonymous
2009-08-29 14:27
28
Name:
Anonymous
2009-08-29 15:07
Sometimes I wonder what happens when a haskellette needs more than 26 variables. Does she use UTF8 or something?
29
Name:
Anonymous
2009-08-29 15:08
>>24
But that's a function name, not a variable name, admittedly elusive to your punny excuse-for-a-brain. That's a pretty good insult, by the way, so right back at ya, bro.
30
Name:
Anonymous
2009-08-29 15:09
>>28
she uses
a',
a'', etc. desu yo~~
31
Name:
Anonymous
2009-08-29 15:09
>>29
I don't know about C, but functions and variables are the same where I live.
32
Name:
Anonymous
2009-08-29 15:11
I don't think this is punny at all.
33
Name:
Anonymous
2009-08-29 15:11
>>30
Nice try, but primes are reserved for names of the iterative loop functions that take additional fixed starting arguments.
34
Name:
Anonymous
2009-08-29 15:12
>>33
not necessarily desu yo~~
35
Name:
Anonymous
2009-08-29 16:06
she
:D
36
Name:
Anonymous
2009-08-29 21:43
>>26
don't be daft, you're supposed to read the line of text backwards
37
Name:
Anonymous
2009-08-30 1:19
>>33
In exposed function names, it generally indicates strictness (e.g.
foldl'). In a
where clause, it generally indicates what
>>33 -san said.
In variable names, it usually means the updated value of an existing variable, or a value corresponding to it in some otherway.
let a' = f a
a'' = g a'
in h a a' a''
(x,y) + (x',y') = (x + x', y + y')
As can be see at
http://hackage.haskell.org/packages/archive/ghc-prim/0.1.0.0/doc/html/src/GHC-Tuple.html#%28%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%29 , clearly
_ is also an option.
38
Name:
Anonymous
2009-08-30 9:34
>>37
you should be using pointfree style for those desu yo~~
39
Name:
Anonymous
2009-08-30 19:02
>>37
DELETE * FROM front_page WHERE posts ARE TOO LONG;
40
Name:
Anonymous
2009-08-30 19:03
41
Name:
Anonymous
2009-08-30 19:07
>>37
from /prog/ import *
shitty_posts = [x for x in [y for y in threads if y.on_front_page()] if x.shitty()]
for p in shitty_posts:
p.sage()
42
Name:
Anonymous
2009-08-30 19:08
>>37
(mapcar #'sage *shitty-posts*)
43
Name:
Anonymous
2009-08-30 23:43
>>39-42
You must be using some strange definition of ``too long'' that was hitherto unaware of.
44
Name:
Anonymous
2010-10-26 22:37