jephthah 1,888 Posting Maven

hmm... interesting. so using that pattern in the directive is essentially the same as fgets() with the "stdin" input, except for not accommodating the null character, and dropping the \newline. otherwise, the amount of "safety" is the same.

i'm rethinking my kneejerk reactionary position against scanf().... it's definitely powerful, but still might be a little abstract for beginners.

jephthah 1,888 Posting Maven

Eff it. i'm gonna learn to fly. i'll figure out how to walk, later.

jephthah 1,888 Posting Maven

meh.

the internet died the day the number of .COM sites outnumbered the number of .EDU site.

i've already mourned and moved on.

jephthah 1,888 Posting Maven

yes, thanks Aia, you're right. i often forget about that. and good catch on the extra parenthesis. that was a typo.

sorry for the confusion.

just a side note, sometimes it's important that a precise maximum number of characters be allowed to be entered by the user, and this value may be defined similar to #define MAX_STR_LEN ... since fgets() always makes room for the null, you would have to add a space to the character buffer

char inputStr[MAX_STR_LEN + 1];

fgets(inputStr, sizeof(inputStr), stdin);

this is where i sometimes get mixed up if i'm not paying attention. it's definitely important to remember when the size of your user's input is critical.


.

jephthah 1,888 Posting Maven

personally, this sounds like a ridiculously hard task for little to no benefit.

i'm not sure why you're even wanting to do what you describe.

i'm not even sure if it can be done.

jephthah 1,888 Posting Maven

Stereotype much?

i knew some people would take exception. yes, i'm sorry, stereotypes are unfair to those who don't fit. but the fact is -- and servers will agree with me across the board -- that you are much, much likelier to get stiffed by one of those groups, no matter how good your service is for them. it's a numbers game, and the odds are against you in those cases.

But people like him are the reason I generally don't tip. They see it as an entitlement and expect it for any piss poor lack of service.

and people like you need to stick to eating at fast food drive-throughs and all-you-can-eat buffets.

if i gave shitty service i expected a shitty (or no) tip. that's why i always gave the best service i could give. like keeping drinks filled, making sure the food was delivered correctly and on time, being aware of when customer needed something... maintaining attentiveness without being fawning or obsequious. all the while helping other servers, and doing behind-the-scenes duties that all servers have to do to keep the front of the house working smoothly.

sometimes, no matter how hard you try, you just completely blow the service for a table. sometimes its not even your fault, the kitchen screws stuff up. in any case i'd apologize and own the problem, and try to remedy it as best i could, and accept the fact that i probably wouldnt get a very good …

jephthah 1,888 Posting Maven

sounds like you could use a little help from Beej.

jephthah 1,888 Posting Maven

you know....

Oregon Trail

rules all.

jephthah 1,888 Posting Maven

don't mind me. i'm just trying to get to 2000.

jephthah 1,888 Posting Maven

"The Dude abides."

jephthah 1,888 Posting Maven

13 states are suing federal government saying the bill is unconstitutional.

WA attorney general has probably committed political suicide by joining this group.

jephthah 1,888 Posting Maven

Diet Mtn Dew is my drink of choice

jephthah 1,888 Posting Maven

... the dangers of dropping acid before going to a keg party, Part 37.

jephthah 1,888 Posting Maven

some bartenders make money hand over fist. most do not. and even the ones that do, its a cycle of boom and bust. the bad days more than offset the good days.

it's not a stable job. you dont see many men or women feeding housing and clothing their families by workign in a restaurant or bar. the ones that do have to support their families on this kind of job, they have it rough.

i waited tables through college, some fairly decent restaurants, and i think i know what i'm saying when i say waiters do not make the kind of money you people seem to think they do.

so, Jew, your figures don't reflect reality. here's why

(1) tables are not always filled. tables are often empty depending on night of the week, time of night, local economy, host(ess) playing favorites, all sorts of other reasons.

(2) tables do NOT turn themselves over every 15 or 20 minutes. i dont know where you go out to eat. Subway? McDonalds? People sit at their table for upwards of an hour or more, getting refills of iced tea or water all night long.

(3) people who have a clue, tip 20%. ignorant provincials, tightwads, jerks, old people, large groups of women, minorities, and all sorts of other people might tip anywhere from 0-10%.

(4) waiters tips do not go in their pocket. they have to "tip out" the hostesses, the bussers, the bartenders, …

jephthah 1,888 Posting Maven

dear sir,

i find your theory interesting, and would like to subscribe to your newsletter.

jephthah 1,888 Posting Maven

Help, help, I'm being oppressed!

jephthah 1,888 Posting Maven

bizarre. it works correctly for me.

are you sure you're compiling the code and then using the executable that you just compiled?

sometime, if i'm not paying attention, i may compile my latest code, but use an old executable.

recompile your code, then check the timestamp on your executable or binary file before you run it. or even put an extra printf statement in there with a unique print output.

the point is to make sure that you are indeed running the code you think you are.

jephthah 1,888 Posting Maven

standard tips are now 20%

tips are taxed, whether they get it or not. if you stiff a waiter on a tip, you actually cause him/her to lose money because they are taxed on gross food sales AS IF they were tipped.

waiters DO NOT make that money you calculated. most of their work is untipped, a lot of prep and cleanup you don't see. they make less than minimum wage for their regular hours.

buncha cheap basterds

jephthah 1,888 Posting Maven

i recommend that you use fgets() instead of scanf().

it's up to you, of course, but best to learn the correct way sooner rather than later.

jephthah 1,888 Posting Maven

sounds like a big project.

show us what you've done so far.

jephthah 1,888 Posting Maven

it takes user input (from keyboard) by using stdin, like so:

char inputStr[MAX_STR_LEN];
fgets(inputStr, sizeof(inputStr)-1), stdin);

... is this what youre asking?

if you want to take input via a file, then check out the example given for fgets()

jephthah 1,888 Posting Maven

it's cool. let us know if that doesn't fix your problem.

jephthah 1,888 Posting Maven

welcome! give a holler if you need any help finding what you are looking for.

jephthah 1,888 Posting Maven

great, and welcome! I'm sure you can be a great contributor to the Hardware/Software forums! :)

jephthah 1,888 Posting Maven

hi, welcome!

you'll find a lot of great help in teh Java and C forums. cant say i know anything about prolog, tho ;)

jephthah 1,888 Posting Maven

hola!

be sure to check out C++ forums, lots of activity and experts there. dont hesitate to introduce yourself and ask a question.

jephthah 1,888 Posting Maven

ah, i thought you were going to tell us you were "a man of wealth and fame" ;)

welcome, hope you find what you need in the forums of your interest. lots of activity in the web development.

holla back if you need help! :)

jephthah 1,888 Posting Maven

because your first arguments to fgets are all single characters.

the argument is supposed to be a STRING. not a single character. a single character is actually an 8-bit integer, so it thinks you are passing in an integer when it expects the starting position of a string (aka character array).

define your character arrays (ie, strings) thusly:

char str1[32];
char str2[99];
char str3[MAX_STR_LEN];

//etc.

or whatever size you need.

and PLEASE use code tags next time. look at your code in the first post. is that even readable to you? its not to me.

jephthah 1,888 Posting Maven

There was a time when fgets did not exist. And people said, "gets works."

no, they said: "use getline()"

It works under certain conditions. It does not work under other conditions.

and those conditions are entirely impossible for the programmer to control. how much more broken does a randomly-exploding function have to be????

Well, as long as there are hackers [minimize, weasel, misdirect].

throw all the red herrings you want, but every computer security expert in the world understands the risk of buffer overflows, and recognizes broken functions like "gets" are the root cause. at the very least it can catastrophically crash the program without any warning. now stop suggesting that people use it, and stop pretending you know better than than the combined experience in the entire body of C programming literature.


look, just bow on out, and go back to BASIC. You seemed to do fairly well over there, and it's become painfully obvious that compiled languages are not your forte.

we've got enough problems to fix. new users break their code and come here for help. not to have it broken some more by someone they assume knows what they're talking about.

.

jephthah 1,888 Posting Maven

gets is still in the documentation. It works.

no, it does not work. arbitrarily writing over chunks of runtime memory is NOT how we define "works"

I wouldn't go so far as to say that it's wrong.

okay, then: it's absolutely wrong.

I would say that it's not safe, not recommended, not the best way to do things.

you're almost right: it's not safe, it's not recommended, and it's the worst way to do "things"

yet, you not only recommended it, but you continue to defend it without pause.

look, we all were prepared to give you benefit of the doubt and chalk it up to an over-eagerness to help. but rather than take a hint, and do some basic research, you now force us to reconsider that you might just be an blooming idiot.

but don't take my word for it. Ask the GNU documentation. Ask the Linux man page. Ask the venerable comp.lang.c FAQ.

Warning: The gets function is very dangerous because it provides no protection against overflowing the string s. The GNU library includes it for compatibility only. You should always use fgets or getline instead. To remind you of this, the linker (if using GNU ld) will issue a warning whenever you use gets. [Bolded terms from original document.]

-- GNU C Library

Never use gets(). Because it is impossible to tell without knowing the data in advance how many characters gets() will read, and because gets() will continue to store …

jephthah 1,888 Posting Maven

ah. now that's something i would have never known :)

jephthah 1,888 Posting Maven

Spaces tabs and blanks will all have a value less than 'A', (hint, hint, hint).

surely you're not suggesting that he blindly remove every char with a value of less than 'A'? because that would wipe out all the numbers and most of the commonly-used punctuation.

lionaneesh, dont make it harder than it needs to be:

to get rid of leading spaces, start at the beginning of the inputString, move through each character that you find a space ' ' (0x20). keep track of the index. once you finally find a character that's not a space, recopy the inputString starting at this location back over the input string like so: strcpy(inputString, &inputString[index]); as for the rest, do what A.D. says, above


.

jephthah 1,888 Posting Maven

@sudiptamondal...
hello mate...i can understand you problem. Seems like we are from same university. WBUT. The most weird university around the globe.

I'm not sure, but I believe it's multiple universities all over India, Thailand, Indonesia, and a few Eastern European countries.

it's unfortunate, but it is what it is. you can advocate for modern compilers when you can. you can ask uncomfortable questions about why they use obsolete crap, when there are modern full featured IDE's available for little or no cost. or you can lay low and learn all you can despite the poor curriculum.

I suggest you spend your time learning how to do it "right" on a modern development and compiler such as MSVC or CodeBlocks+MinGW. Know that any code that is compilable in a standard-C compiler, will also work on Turbo C.

when they force you to use the archaic crap, like "graphics.h", just do what they require. if you have the motivation, also try to learn to do graphics using the OpenGL or GTK+ libraries. CodeBlocks supports these industry standard graphics libraries. learning them will only benefit you.


.

jephthah 1,888 Posting Maven

oh, well, you have an awesome command of the english language. i thought you were a native speaker.

i feel bad for you guys out there. a bunch of really good talent, sadly being instructed in an educational system that perpetuates incompetence in the administration.

jephthah 1,888 Posting Maven

I'm not embarrassed to admit that I haven't a clue about what you're talking. However, I do have Super Secret Investigative Powers, so i was able to find out:

CUDA (an acronym for Compute Unified Device Architecture) is a parallel computing architecture developed by NVIDIA. CUDA is the computing engine in NVIDIA graphics processing units or GPUs that is accessible to software developers through industry standard programming languages. Programmers use 'C for CUDA' (C with NVIDIA extensions), compiled through a PathScale Open64 C compiler, to code algorithms for execution on the GPU. CUDA architecture shares a range of computational interfaces with two competitors -the Khronos Group's Open Computing Language and Microsoft's DirectCompute. Third party wrappers are also available for Python, Fortran, Java and Matlab.

so i don't think youre going to get much help here. this is far too specific of a niche application. we generally don't deal with proprietary extensions. We can't, really. Questions about proprietary libraries are far better handled by people with expert knowledge in the specific libraries.

good luck

.

jephthah 1,888 Posting Maven

i'll take back my neg assumptions of your instruction/curriculum. i thought you were from the indian subcontinent, or southeast asia. because they apparently have entire universities that force students to use Turbo C for some unknown reason. since you're from a western country, your instruction is probably adequate.

yes, do uninstall that compiler. it is bad. There are many good options, including MSVC. I recommend the free Code::Blocks. download the windows version that comes with MinGW compiler, it's fully modern and adheres to industry standards.

as for "fgets" its from the same <stdio.h> library that "scanf" is in. there's no reason to think you're not advanced enough to use it. Check it out, .

good luck.


.

jephthah 1,888 Posting Maven

sending a file to a printer is going to be highly specific to your OS and your particular environment. is your computer on a network or is it locally controlled?

consider printing your receipt to a text file, then opening it up in a text viewer (notepad or gedit) and printing it directly from the viewer.

jephthah 1,888 Posting Maven

this thread has been marked solved. if you ahve a qeustion, start a new thread.

and DO NOT post the same kind of crap you posted up there.. it doesnt make any damn sense, and i dont think it's even a question.

DO NOT post 156 error messages. in fact, dont post any. we can figure it out.

DO post formatted and indented code. use the (code) button on the top of the message box that you type your question in.

jephthah 1,888 Posting Maven

you found a rather interesting and little-understood tidbit in the scanf() function..

note the string has a space ' ' before the specifier: scanf(" %[^\n]",line); ... this is just as critical as the odd-looking format specifier.

from the IEEE Standard:

A directive composed of one or more white-space characters shall be executed by reading input until no more valid input can be read, or up to the first byte which is not a white-space character, which remains unread.

while the %[^\n] excludes newlines from the list of readable whitespace,... meaning that a newline will flush the input buffer and send all input to the character array.

it's kind of neat.

#include <stdio.h>

int main (void)
{
    char line[200];
    while(1)
    {
        printf("\nenter a string: ");
        fflush(stdout);         // safety flush since no newline in printf above
        scanf(" %[^\n]",line);  // note space character
        printf("you entered >%s<\n",line);
    }
    return 0;
}

you can try alternate builds where you remove either the single space, or the %[\n] and see what happens

i will say that, while it looks pretty cool, it appears that you can't protect buffer overruns, like you can with fgets...

i'll also admit i'm a little fuzzy on how exactly this directive is interpreted.

jephthah 1,888 Posting Maven

i've reconstructed this in in my text editor and fixed the indentations, and it's not terribly hard to read.

but we will need that "def2.h" file. I'll bet that's where all the missing info is that Aia is asking about

i was going to note that i don't see any reference being made to the "charger()" function (translate "load") but then i also don't see a "main()" function. where is main()?

jephthah 1,888 Posting Maven

i can see your point. there's value to keeping it simple. and often i won't bother trying to correct the use of scanf(), when the issue being addressed is unrelated.

but in this case, i disagree, because the very problem is due to scanf(). it doesnt take Miss Piggy to come along and fatfinger a user entry all to hell. So your getchar() is just putting lipstick on a pig. And then walking that pig to a synagogue on Yom Kippur. While munching on a bag of pork rinds.

wait, what?

okay, never mind. i'll agree to disagree, and leave your scanf()s alone from now on.

.

jephthah 1,888 Posting Maven

I'm aware of [ the problem with "gets" ]. But I just think that the user needed some simple help. But to get the user started, it helps to not get them bogged down in all the fine details.

i hear what you're saying, but sorry man, but you're totally wrong in this case.

there is sometimes value to keeping things simple.... For instance one could make an argument about using "rand() % 6" to roll a die, rather than getting "bogged down" in the finer points on the nature of pseudo-random generators.

but the ugliness of gets(), the pure incompetence behind using it, is beyond any considerations of simplicity. if there is ever one universally agreed upon rule in C programming, it's this: never. use. gets().

if you want to put a huge hole in your programs, no one will stop you, but shouldn't admit it in public, and absolutely never recommend it to new users who likely don't know any better.

jephthah 1,888 Posting Maven

first consider:

char letters[7] = {"ARVGMNB"};

for (i=0; i<7; i++)
   printf("letter # %d = %c\n", letters[i]);

then consider:

int number = rand() % 7;
print ("random number from 0-6 is :  %d\n", number);

now somehow you need put em together in your program.

.

jephthah 1,888 Posting Maven

welcome! you'll find our C++ is very active . plenty of experts who can answer all your questions.

jephthah 1,888 Posting Maven

welcome. hope you find what you're lookign for. C, C++, Java, and Python are very active forums.

jephthah 1,888 Posting Maven

But now how would I go about reading and printing each character of the input word?

i handed you two scenarios to do exactly that.

If you can't bother to read the answers in your own thread, i have no interest in helping you any further.

jephthah 1,888 Posting Maven

yeah, lseek doesnt read backwards. because seek doesnt read. seek just moves the file pointer to a relative position. lseek moves it to the "left" (ie, backwards)

file reads are always done in the forward sequence.

a better way to read something in reverse, is to first read it from the file as normal, into a character buffer in memory, then copy it backwards into your target buffer by decrementing the index or pointer.

walt's suggestion is very literal minded. Like the genie in the lamp granting wishes, he gave you exactly what you asked. it would be a huge resource hog for any sizeable file.


.

jephthah 1,888 Posting Maven

its all good. no apologies needed, i can be a bit terse.

while( 1 == 1) //That what you meant by infinite loop?

yes thats an infinite loop. while(1) would accomplish the same. I suggest you use the "break" statement to cause an early break out of the while loop. then return "nrolls" from the end of the function. the way you're doing it, works, but it's sloppy and some compilers will throw a warning. this and other types of bad coding practice are the source of many bugs. i've seen where oddly placed conditional returns have been the root cause of some nightmare debugging efforts.

also you should check that the value is indeed between 1-10, since that's a condition you specify, and zero or negative input will cause bigger problems later.

try this:

int nDice( void )
{
   int nrolls = 0;

   printf ("Please enter the numerical amount of dice you would like to roll (maximum 10):\n");

   while( nrolls < 1 || nrolls > 10) // force a meaningful value to be entered
   {
      if ( scanf("%d", &nrolls) !=1 )
         printf ("\nI'm not even programmed to recognize what you entered, so I'm guessing\n"
                "that it wasn't even a number. You Sir/Madam, are retarded. Read the directions\n"
                "and try again.\n\n");

      else if (nrolls < 1 || nrolls > 10)
         printf ("\nWrong value, jackass.  try again.\n\n");  // hey, you want insults, right?
   }

   return nrolls;
}

.

jephthah 1,888 Posting Maven

try this:

int main(void)
{
    const char constString[32] = "Hello World!";
    char *myPtr = &constString;

    while(*myPtr != '\0')
    {
       printf("address 0x%p:   %c    0x%02x\n", myPtr, *myPtr, *myPtr);
       myPtr++;
    }

    return 0;
}
jephthah 1,888 Posting Maven

pointers.