No ... I'm pretty sure it's photoshopped. See, you can tell by the pixels. And I should know, because i've seen a lot of 'shops in my time.
(PS: weeaboo.)
No ... I'm pretty sure it's photoshopped. See, you can tell by the pixels. And I should know, because i've seen a lot of 'shops in my time.
(PS: weeaboo.)
I wanted to know why you would disapprove of someone admitting a mistake, or why you would even get involved.
(1) i'm not "disapproving of you" or your "admission of a mistake" -- i negatively marked a post that was both inappropriate and unhelpful. sorry if it hurt your feelings.
(2) as to getting involved, let me ask this: For someone who admits he "doesn't know C programming" why are YOU even trying to answer questions in a C language forum? dont you have some PHP to go look at or something?
(3) we're talking about what was a net loss of six (6) freaking points. are your little feelings that sensitive? are you that wrapped up in reputation points as some measure of your personal self worth?
I mean, get a life already. quit being such a whiner. if you recall, old J.C. wasn't a whiner. He manned up and took all the neg rep handed to him.
i dont think you're doing a good job at all of measuring up to your self-appointed namesake. maybe you should change it to "BestJewSinceSimonPeter", because as i remember, that guy was always complaining about something or other.
.
dammit!
i want my dollar back.
:angry:
yeh, King's a real schmuck, but he's in a solid conservative district with no opposition.
if they can even find someone to run against him, it's been estimated it'll take about $50 Million to unseat him.
good luck with that.
Why would you give me bad reputation
"i dont know but here's google" may be appropriate in some cases, but Monkey_King posted a decent question, included formatted code, described the output he wanted, and asked why wasnt it working exactly the way he anticipated.
And the answer is not so easy, because strtok() is a difficult function for inexperienced programmers to understand from just a basic description.
to post a snarky, unhelpful RTFM-style answer is totally appropriate for newbs or other lazy sods who just want someone to do their work for them. But Monkey_King, as evidenced by the clarity of his post and the effort he made prior to posting, is obviously not in that group.
there are plenty of unhelpful or inappropriate posts on these forums. But i found your Post #2 to be both unhelpful and inappropriate so i neg-repped it. tux4life, as it turns out, disagreed with me so he pos-repped it.
now measured by net gain, you have come out ahead, gaining even more more rep points than Tom Gunn, the one person to actually post a thoughtful and correct solution.
so be proud. you scored. :) and for someone who "doesn't know, but can use google", you did a good job whining for your rep
.
although I don't understand why did you use IF condition
this is not your thread to ask basic questions. go open your own thread on how to use IF.
and if you don't know how to use sscanf() -- much less how to look it up -- then you damn sure need to quit "helping" people.
.
how to extract some character/number from a char string?
Example:
char = TAGNAME_C123_V45_S67_M89
what you have written here is an identifier from a #define
'd constant -- not a string.
if it were a string, then you could use sscanf() as Tom Gunn suggested. but he's assumed that you really meant to put something like char *p = "TAGNAME_C123_V45_S67_M89";
... and that is not what you wrote, since it was not in quotes.
if TAGNAME_C123_V45_S67_M89 is a constant identifier -- as it appears to be -- then you can not merely use sscanf() to extract substrings out of the identifier name. it becomes more complicated, and you will have to rewrite a significant amount of code.
if you truly meant it to be a string, then it must be in quotes and either (1) assigned when declared as a const char *
, as Tom suggested, or (2) assigned later with a function like "strcpy()"
the difference is important, and will significantly affect how you accomplish what you want to do.
.
kernel32.lib can't be found. I've found the library in some Microsoft SDK folder and I add that to the library search path but ... something is wrong.
your .NET installation is broken. Unless you're some sort of windows/.NET guru, the chance of you fixing it correctly is small.
uninstall all visual studio and .NET components, reboot, then reinstall.
$350 a lid?
holy shit, you kids these days.
:icon_rolleyes:
Ive never seen a water tower before.
wut?
LOL WUT
.
i made a mistake. i said the OP who suggested that programmers were stoners was from the u.s. midwest... that's not correct. Menster is apparently from Australia.
so let me make my own overly gross generalization:
the reason you think all programmers are "stoners", Menster, is because you're from Australia. and as the rest of the world knows, there's no significant tech development coming out of Australia.
Now i can't say if that's the cause or the effect of you guys being a bunch of potheads, but there must be some connection.
Why, it would taste like Jello.
well, i can see you're the real life of the party, aintcha?
a vanilla and walnut flavored Jell-O bun, pistachio flavored lettuce, cherry and cherry cream Jell-O tomatoes, chocolate and chocolate mousse flavored Jell-O burger, orange-lemon Jell-O cheese, lemon-lime Jell-O pickles, and coconut flavored Jell-O onions.
because that's just awesome.
I am amazed.
that hamburger and fries is crazy. i'd love to be on the judging team to sample those.
Yeah, and Hempfest is coming up soon. I wonder if Seattle's former Chief of Police, Norm Stamper, will be there speaking on behalf of marijuana legalization/reform.... again.
:D
A function definition is also a prototype, so you don't need to split them up
i'm glad you find it so exciting to point out that a function definition, by definition, includes the prototype.
but i'm explaining a basic concept to an inexperienced user here, not defending a dissertation to the pedantic professor.
the point remains : either place a prototype ahead of the first use, or define the function entirely ahead of the first use.
.
this is a bizarre correlation that you've made, that most programmers are "stoners".
i don't really know many programmers who are "stoners". most of them are intellectual types (or even downright "nerds") who aren't especially prone to partying.
granted *some* of them can be grouped in what you would classify as the "stoner culture", but those tend to be more of the unprofessional, undereducated, overgrown skript kiddies --- you know, the self-taught, PHP webpage jockeys who spend more time playing MMORPGs than producing code.
now, I'll admit: maybe my opinion is colored by my area of the country. I'm in Seattle, where two things may be quite different from your area of the US Midwest.
(1) we have a huge professional programming community (think: The Software Giant in Redmond), most of whom are highly educated and motivated.
(2) we also have a culture that doesn't much give a damn about who smokes a little pot in their private time. Marijuana use has been all but decriminalized here, so most people don't get their drawers all in a bunch about it.
Disclaimer: I don't smoke pot, and I don't much care whether anyone else does or doesn't.
.
that's a photoshop, you can tell by the pixels.
if you define the function after it is called by the code -- such as in "main()" -- the compiler needs a prototype to know how to handle the function when it runs across it in the code. otherwise, it has no clue what the function is and whether or not you've called it correctly.
IIRC, older (pre-ANSI) C compilers typically assumed a default of 'int' for return value, but newer compilers do not have to do so.
Basically it comes down to this: If you don't either (1) prototype the function or (2) fully define the function prior to its use, you will be setting yourself up for a variety of potential problems.
.
For those with a below-par grin ...smile-boosting messages will pop up on the computer screen [such as] "lift up your mouth corners",
umm... yeah.
You know what? Japan is kind of weird.
Hey, Look!
It's AIA!
:)
this thread made me laugh.
and, no. i haven't.
take A.D.s advice :P
After adding malloc ,this code compile and execute perfectly ... can u explain it?
'k' is a pointer. meaning it describes, or "points to," an address of memory.
when you first declare this pointer, there is no memory allocated for it and the address that it points to is undefined.
malloc() then causes a location of memory to be allocated (in your example for a single integer) and the pointer 'k' is assigned to the address of this allocated memory space.
the *value* contained at this memory space is still undefined, until the line of code *k = 10
, which assigns the value 10 to the memory pointed to by 'k'
as wildgoose suggested, to use malloc for a single integer is not very practical. malloc is for dynamically sizing arrays, not single variables. you should not get in the habit of using it like this. You should instead do it the way he showed you in Post #2
in any event, it will make more sense to print the address as a hex value. use the format specifier '%p' to print a pointer as a hex address: printf("address %p = %d\n", k, *k);
see http://www.faqs.org/docs/learnc/c620.html
.
but fgets reads strings can it read ints 2 ?maybe if i read a string and convert to int by atoi ?
that's one way to do it. I prefer to use "strtol()", because you can do more robust error checking to see if the user entered a valid number.
but sure... try "atoi()" to get started.
.
fflush(stdin) is totally, utterly, and completely wrong.
never, ever, use it.
learn to parse your input correctly in the first place, and you wont have this problem.
so get rid of scanf() while you're at it. that's a bad function to use, and is a source of the problem.
use fgets() instead, and parse the input to find the data you're looking for.
Swearing / use of cuss words is not allowed in the channel in case you didn't know. ;-)
eh, we did an experiment and it appears that only s--t and f--k are bootworthy. anything else seems to be fair game.
hmm... i just reread your post, i thought you were experienced in another language, but i see now that's not so much. (by the way, HTML is not a programming language, it's a markup language... just FYI.)
K&R was not really written for novice programmers. It's written for intermediate programmers who are learning C, but have a foundation in some other structured language
perhaps you might want to check out one of those Teach Yourself C books. like the Sam's series or the "____ For Dummies" series. I'm not recommending these,they don't have much professional credibility, but they will hold your hand through some of the beginner stuff.
just borrow one from the library, just long enough to build up some confidence in basics --- then come back to K&R
.
if you want to round the number, then you use "setprecision(<n>)" or the format specifier "%.<n>f" for "printf()" where <n> is the number of digits you want to round to. E.g., the value 1.66667 rounded to <n>=1 decimal place will be 1.7
but what you really want to do here is truncate. this means just "chopping off" (so to speak) all digits past the desired place will just be thrown out, and the least significant remaining digit will not be rounded.
to truncate a value, then, you need to use the "floor" function (for positive values, see caveat* below). but since this returns only a whole number, you will need to first "shift" the value to be truncated a number of decimal places that you want to truncate, floor the value, then shift them back.
(note my use of the word "shift" here is not a bitwise shift, because we're talking about decimal places, not binary places -- you will have to multiply by powers of 10)
value = 1.66667;
truncValue = value * pow(10,1); // shifts dec. pt. 1 place right
truncValue = floor(truncValue);
truncValue /= pow(10,1); // shifts dec. pt. 1 place left
you can replace the '1' with a variable to allow variable truncation.
*caveat: this will not work for negative numbers. example value = -1.666667 rounded to 1 decimal point would be -1.7, and truncated to 1 decimal point should be -1.6.
However, if you used "floor" on this negative …
IRC is the "Mos Eisley" of the internet
nah, that would be Craigslist.
you dont get arrested or killed on IRC.
I Third the vote for Code::Blocks
get the version "codeblocks-8.02mingw-setup.exe", it comes with the MinGW (gcc) compiler, and you cant go wrong. it's an industry standard.
I would not recommend that you use a text editor and stand-alone compiler to learn.... that will increase your frustration. i used to program that way for years, and now that i've finally moved over to IDE (integrated dev. environments) i wouldnt want to inflict notepad programming on anyone. its like going from dialup to broadband: you'll never go back.
otherwise, do stick with K&R's "The C Programming Language". you'll be better for it. you *could* get one of those "Teach yourself C" type of books, but you'll be cheating yourself.
i've just revisited the K&R book, and it is superior. make sure you use the Second Edition, though, that one is compliant with ANSI C.
also, you can get "The C Answer Book" by Tondo and Gimpel, published by Prentice Hall. It contains fully worked out solutions to all the exercises in K&R.
Borland from ages past, as in late 80's - mid 90's? i hear ya, but c compilers have changed since then, while borland has all but shit the bed.
but yeah, Microsoft is famous for making their stuff, um, "helpful" :icon_rolleyes: thats why i prefer to stay with GCC. (except at work, i have to use National Instrument's peculiar C libraries....)
This thread has been marked solved
aha. i guess he found what he was looking for?
Hi,
I am interested in doing Phd in computer science. Can anyone help me in finding a suitable topicwaiting for early reply.
here's an early reply: get your PhD in post-hole digging.
i mean, jesus.
if you need an internet chat forum to tell you what your career research focus will be, you probably should go on and get out of academia now.
If you could just tell me how to set a socket to non blocking and explain select() to me I'd be grateful.
http://tangentsoft.net/wskfaq/examples/basics/select-server.html
i find it pretty incredible that a professor would dump all this at once to beginners who had never passed arguments to functions before
%i and %d are equivalent. both of them specify the format for a signed decimal integer, and either are acceptable to use
just as an afterthought, i should clarify that the above statement is only strictly true for "printf()"
for "scanf()", the %d and %i are subtly different ... %d requires a decimal (base 10) integer input, while %i assumes decimal by default, but will also read number as octal if it is prefixed by '0', or hexadecimal if prefixed by '0x' or '0X'
"Ignorance is bliss"
your ignorance is contagious. please stay back i don't want to catch it.
well, that's a nice bit of feature creep to throw out there at the last minute.
do you work in marketing?
i remember the frustration of being versed in a couple languages, but not knowing where the hell to start when faced with another language i'd never used.
:P
most of these trifling problems will go away when you throw away the P.O.S. Borland/Turbo compiler and get a real C/C++ compiler like CodeBlocks or Bloodshed Dev C++.
these GCC-based, standard C compilers wont let you use worthless functions like flushall(), obsolete libraries like conio.h, and will complain heartily if you try and hang yourself by using gets()
.
the answer to your basic problem:
if isdigit(cResponse);
is incorrect. it should be
if (isdigit(cResponse))
{
// do stuff here
}
(1) an if-statement must be entirely enclosed in parentheses.
(2) an if-statement -- if the condition is evaluated as true -- will execute either one line of code terminated with a semi-colon or a block of code contained between the curly braces, '{' and '}'
so even if you framed the conditional statement correctly, since you put the semicolon directly after the if statement, it still would never execute anything when the condition evaluated true.
.
oh
what a dumb mistake i made
sorry, thanks for help
if it's a dumb mistake, then we're all dumb. even experienced programmers will sometimes forget to initialize variables. it's probably one of the most common bugs.
:)
some compilers will initialize variables to zero. but there is no requirement in the C "rules" for them to do so.
therefore, most compilers will not initialize variables you declare, and so their contents are undefined until you do so. they will contain whatever bit pattern previously existed at whatever memory location is being used, and will likely result in some very large positive or negative number.
So never assume your declared variables are initialized. be certain that you have initialized them, or have otherwise set them to equal some known value, before using them.
.
looks like you're on a Linux platform, yes? so you should have the Gnu C Compiler (gcc) available.
put the files you want to compile in one directory, and invoke the GCC compiler like so
gcc -o <binaryName> <source1.c> <source2.c> <...>
where binaryName is an arbitrary name of the compiled binary file, that will be compiled from the source code.
for example, http://www.json.org/JSON_checker/ ... has three files: JSON_checker.c, JSON_checker.h, main.c
the header file (.h) is #include by both of the .c files, so if it's in the directory that you compile in, it should be found automatically.
compile it into a program called "checker" by placing all three of the files in a directory, then invoke gcc, like so:
% gcc -o checker main.c JSON_checker.c
to run the program, you would call it from the directory
% ./checker
this particular program requires an argument to be passed, a file that will be checked for correct JSON syntax. so you will get their example files, or create one yourself, and pass the filename as argument to the program
% ./checker test/pass1.json
(see comment from the "main.c" file)
wildgoose: posting "Untested" code on daniweb's C forum is generally risky business :P
anyhow, being able to use strtok() correctly is tricky for a new user. Also make sure you understand what is going on with strtol()
char string[100]="+1236,,..,,actgn+3ACT-4CCCC";
char *token, *ptr;
int value;
token = strtok(string,"+-");
printf ("found numbers: ");
while (token != NULL)
{
value = strtol(token,&ptr,10);
if (ptr != token)
printf(" %d,",value);
token = strtok(NULL,"+-");
}
printf("\n");
.
Does anyone have an idea if this can be done smarter, better, faster?
check out: strtok() ... this breaks a string into tokens at each of one or more delimiters.
use it to break the string at each '+' or '-' (the delimiters), then check if the first one or more characters of each resulting string (the tokens) are numerals.
if it does, then push that number onto your result array. if it doesn't, skip on to the next token.
.
There is no political solution
To our troubled evolution
Have no faith in constitution
There is no bloody revolution
We are spirits in the material world
Are spirits in the material world
Are spirits in the material world
Are spirits in the material world
Our so-called leaders speak
With words they try to jail you
The subjugate the meek
But its the rhetoric of failure
Where does the answer lie?
Living from day to day
If its something we cant buy
There must be another way
We are spirits in the material world
If the code is already there, you might as well help make it better and hope the guy learns something instead of sitting on your **** waiting for him to fail at life.
or, conversely:
you post your code there, and wait for someone to make it better and hope some guy doesn't expect you to actually learn something, and you can just sit on your ass waiting for handouts all your life
And he can ask questions. That's how it works in most places. See something you don't understand, ask about it, get an answer, and learn.
O RLY?
and where are these "most places" of which you speak? The ones where people ask questions to get answers? Because it sure isn't here.
DoEds
Newbie Poster
Posts: 1
.