jephthah 1,888 Posting Maven

try this

#include <stdio.h>
#include <string.h>

int main(void)
{
    char myString[32];
    int length, i;

    strcpy(myString,"Hello World!");
    length = strlen(myString);

    for (i=0; i<length; i++)
    {
       printf("index %02d :   %c    0x%02x\n", i, myString[i], myString[i]);
    }

    return 0;
}

.

jephthah 1,888 Posting Maven

Add this right after your scanf()'s:

getchar();

this is wrong. its sloppy and it barely addresses the problem. in practice, with more complex inputs, it will fail more often than it works.

if the user enters a number followed by enter, like this: "12\n" , adak's suggestion will work

but if the user input diverges from that in the slightest (and it will) ... if they enter other stuff after the number (a "\tab" or a space " " or some other input), like this: "12 \n" ... it will still fail to work correctly.

do not use scanf. use fgets to a string, then convert the string to an integer, long, float or double using "atoi" "atol" "atof" or "atod"... even better are the functions "strtol" and "strtod"

.

jephthah 1,888 Posting Maven

the quick answer is that youve got unbuffered input due to your use of scanf()

but you've got a number of bad programming practices here, that i can't ignore. I suspect the blame is due to incompetent instructors teaching substandard curriculum on compilers that are 15 years out-of-date.

So I'm just going to lay it out, and if you choose not to take this advice ... well, at least I told you.

the non-standard <conio.h> library is obsolete. cease using it. this means that you will not be able to use things like "textcolor" which is unnecessary now that the days of DOS has been over for at least 10 years, and "clrscr" which is always obnoxious. you will not be able to use "getch" either, but don't worry the standard-C library <stdio.h> has "getchar" which will suffice. But you'll really want to use "fgets" anyhow, for most console input.

do not use "exit()" to quit a program due to normal events. this is a terrible practice, and will cause all sorts of problems once you start writing real programs that interface with real hardware and live databases.

steer away from using scanf(). the lure is tempting, but you need to learn to avoid it. its the source of many problems. fgets() will get a string safely that can be converted to numeric value and allows a relatively easy error-checking method to ensure the input buffer is cleared in case input is too long. (i'm …

urbangeek commented: Awsome...thanks!! +0
jephthah 1,888 Posting Maven

do not make it global. that is not good advice, and doesnt fix the root of your problem.

i do agree that you need to use fgets(), instead of scanf(), because scanf() should never be used to input strings. scanf will not accept anything further once you pass in a whitespace.

your real problem here is that in your string size of 100 characters, everything beyond the end of the input string is garbage, and your reverse function is attempting to print all that garbage.

say you enter the string (using fgets!) that reads "hello how are you". this gives a string of length 18 characters: the 17 characters and spaces, plus the newline character. (note that you would need a char[] array of 19 to hold it because of the guaranteed terminating Null character.)

the remaining 81 characters is random garbage. you do not want to print those, you only want to print the first 17 characters that are valid.

do something like this in your "reverse()" function:

length = strlen(str);
    if (str[length-1] == '\n')
    {
        str[length-1] = '\0';
        length--;
    }
    for(i=length-1;i>=0;i--)
    {
        printf("%c",str[i]);
    }

Note: "strlen()" requires that you include the <string.h> library.

.

jephthah 1,888 Posting Maven

in your "count()" function within the body of the "for" loop, test if the character is a space ' '. if the character is a space, then break out of the for loop early by using the "break" command.

if you want to be thorough, test also for \newlines and \tabs

if (c == ' ' || c == '\n' || c == '\t')
   break;

finally, make a nominal effort to spell words correctly. you are not posting from a SMS texting cellphone, so typing "wut" and "wud" and "tat" and "wen" makes you look like a goddamn willful retard. If you do it anymore, i'm never going to help you again.

.

jephthah 1,888 Posting Maven

sounds like you have a good program. we had a "co op" program that allowed work-study, but it was optional and many people didnt do it because it delayed graduation by a year.

i graduated right after the tech bubble popped and a lot of experienced developers were out of work. it was a very anxious time. i spent my last semester sending out scores of resumes and letters and filling out applications. as it turned out, i got hired right before i graduated, and was able to start right away.

since getting my BSEE, ive worked in a few different industries: construction, telecom, scientific instruments, and now medical devices.... i'd like to stay in medical devices. i find it challenging, rewarding, and i feel it has a sense of social purpose.

the thing about that first job, it will really determine the course of your career. yes, you can change paths later, but it becomes more and more difficult. I would recommend that you take that first position in the industry want to be in and doing the kind of work you like, and not just taking a job because it's available.

good luck. :)

jephthah 1,888 Posting Maven

as you probably know, Ping is on the Network Layer, and by definition doesn't use a port. there is no such thing as "Tcp Ping".

problem is, many servers no longer adhere to the RFC requirement to answer a network ping, citing security risks.

so, some people have written their own programs to emulate "ping" functionality at the TCP Transport Layer.

you could either get busy and start writing your own from scratch, or search around and use somebody else's.

like this
or this
or this.

jephthah 1,888 Posting Maven

Please understand that Turbo, no matter how old
1) is in use
2) works
3) is not going to get replaced because you don't like it.

And stop regurgitating hatred for something you've go no business even commenting on. It's getting old.

"in use" ? really? where?? name for me a credible software company that uses Turbo C to develop meaningful, widely-distributed software for the commercial sector.

"it works" ... hey that's a good criteria ... an abacus works, too. perhaps we should teach business students how to balance ledgers with an abacus. and, by the way, don't let your definition of "Turbo C works" include crazy things like multithreading.

"wont get replaced because you don't like it"... hey, i'm a one-man army on a mission from god.

"stop regurgitating ... got no business ... getting old" how about we look through the past month or two of your posts and count the number of rants where you go off on people for using Turbo C. i'm noticing you have a pattern of harassing members for the exact same behavior you engage in yourself. :icon_rolleyes:

.

Salem commented: "It's a 106 miles to Chicago, we've got a full tank of gas, half a pack of cigarettes; it's dark, and we're wearing sun glasses. Hit it!" +19
jephthah 1,888 Posting Maven

indeed.

there's always room for another 73-page thread of opinions on U.S. politics on the interwebs.

jephthah 1,888 Posting Maven

I doubt it was merely a coincidence. It was in fact well planned, with whatever differences designed for input vs. output.

okay, fine, it was a well planned effort to trick new programmers.

jephthah 1,888 Posting Maven

perhaps you didnt notice the text, right above the message entry box when you bumped this thread, that reads

This thread has been marked solved.
Perhaps start a new thread instead?

it's bad form to reopen someone else's solved or closed threads. unless you have a specific question precisely about the original post or one of the responses to the original post. In which case you need to make your question or comment very specific and clear, so that it's relevance is apparent to all.

please do not just wake up some old post with a generic "hey did this work?" question.

Instead, formulate your own question that relates to what you are doing, and supply a short and concise code example of what you're trying to do, and put it all in a new thread.

.

jephthah 1,888 Posting Maven

1-11: imagine you have a program that counts the number of words that it takes as input.

how does the program take any group of characters and determine where the words begin and end? by the existence of "whitespace" separating each word, right? Remember, whitespace can be a space ' ', a tab '\t', or a newline '\n'.... So basically the program looks at each character in the input string and when it finds whitespace, it counts the preceding group of characters as a word

(a) if you had a program that performed this function, how would you verify it? how would you show that the program did indeed count the correct number of words given some input.

(b) and in this program, what could be a likely source for an error to occur? is there some event that could, say, cause a miscount? again, think of how words are counted. by the separation of words between the whitespace (space, tabs, newlines). For instance, is there a case where you could have some whitespace in the middle of a word, but it should only count as one word and not two? Or conversely, can there be a case where two words are not separated by whitespace, but they should be counted as two words and not one?

1-12: write a program to do the following:

(a) accept a string of text input
(b) separates each word in that string so that it prints one …

jephthah 1,888 Posting Maven

i tell ya whats annoying. when i forget to enable Adblock Plus, and i keep getting that stupid big popup ad at the top of the page. but then i remember to enable Adblock and it's all groovy again.

hello? hijack, what?

oh, sorry. carry on.

.

jephthah 1,888 Posting Maven

[EDITED]

nevermind. lets not go there. daniweb is a such a nice site.


.

jephthah 1,888 Posting Maven

im not ever a moderator, and the thought of implementing and maintaining a wiki for this site sounds like pure hell.

if you really think it's tenable, why dont you give it a shot? you can make the "Unofficial Daniweb Wiki".

see what happens.

.

jephthah 1,888 Posting Maven

Nick, you know i love you, man

:P


.

jephthah 1,888 Posting Maven

welcome Mario! I'm resisting the urge to say, "Hey! It's a me, Mario!". So far so good. Wait, what? Oops

haha never mind me. :P

best wishes following your dreams. it sounds really cool, and i think you can do it.


.

jephthah 1,888 Posting Maven

great attitude :)

my family is from Pittsburgh, and i lived in Cleveland for a time, so i know about cities having undeserved bad rep. all have their good points and bad points.

good luck in your certificate. not familiar w/ it myself, but im sure some of the forums here can help you with particular areas you want to develop skills in

jephthah 1,888 Posting Maven

I dont have any specific help, but you should go post in the "Databases" forum, under the "Web Development" heading

jephthah 1,888 Posting Maven

well, dammit, i wanted a joke. i guess if you're starting them without finishing, ill finish without starting!

redneck 1: "sure is cold."
redneck 2: "and deep, too."

jephthah 1,888 Posting Maven

:-P

jephthah 1,888 Posting Maven

eh, forget about it.

i'm not really smart enough to be a geek. i'm mostly a dork. just ask my wife ;)

jephthah 1,888 Posting Maven

hey you old coot. :)

finding what you need yet? got any specific questions?

jephthah 1,888 Posting Maven

Hi and welcome! hope you find what you need.

Detroit, huh? i thought that city closed down.... glad to hear people are still there.

jephthah 1,888 Posting Maven

advice? get a degree. two-year AAS degree in computer technology (or similar) from your local community college. not having any degree means you will perpetually have shitty jobs and low pay. a nominal tech degree will allow you to work some place they don't treat you like a serf.

just do what it takes to get through your math courses. plenty of tutors and help from instructors if you ask. it's really not that hard. you may even find a new appreciation for math once you get out of H.S.

jephthah 1,888 Posting Maven

i, too, am a wannabe.

anyhow.... welcome, eh!

jephthah 1,888 Posting Maven

Hallo Taskone und Wilkommen! :) Wie geht es Ihnen?

jephthah 1,888 Posting Maven

hi and welcome! hope you find what you need :)

jephthah 1,888 Posting Maven

hi and welcome! hope you find what you're looking for :)

jephthah 1,888 Posting Maven

hi and welcome! i think youll find this a good student resource if you use it. good luck in your studies :)

jephthah 1,888 Posting Maven

hi and welcome, david from manchester! hope you find what you need :)

jephthah 1,888 Posting Maven

hi and welcome! sounds like youre in the right place. hope you find what you need :)

jephthah 1,888 Posting Maven

sounds cool. im sure theres a lot of database work and front end webpaging that could really help you with your job.

not my cup of tea, but I'm sure you'll find a lot of people here with similar programming interests!

jephthah 1,888 Posting Maven

hi and welcome, syphil! hope you find what you need :)

jephthah 1,888 Posting Maven

hi and welcome, Serbia! hope you find what you need :)

jephthah 1,888 Posting Maven

hi and welcome! hope you find what you need.

don't worry about not knowing anything. letters after your name is all that matters in many businesses. the dirty secret is, most people dont really know anything either. and i personally feel stupider every day.

but otherwise, cheers!

jephthah 1,888 Posting Maven

hi and welcome! congrats on the recent graduation. hows the job search going? already landed or still looking? just curious, i majored in EE also, and getting that first job out of college was fairly critical.

jephthah 1,888 Posting Maven

hi and welcome! i see you've made your entry into C forums. see you around :)

jephthah 1,888 Posting Maven

Hi Adam Paulson, and welcome! hope you're finding what you need :)

jephthah 1,888 Posting Maven

haha. thats funny. i use that strategy too. it works :)

anyhow, welcome... hope you're finding what you need :)

jephthah 1,888 Posting Maven

hi and welcome! hope you're finding what you need :)

interesting place you work. a decent website, but it does load rather slow.

bummer about your name getting filtered. I know a lot of similar stories, but most of them probably arent appropriate to tell here :)

jephthah 1,888 Posting Maven

hi and welcome, Steven Campbell! hope you're finding what you need :)

jephthah 1,888 Posting Maven

hi and welcome! hope you're finding what you need :)

disclaimer: i hated the one and only human factors class i took.

jephthah 1,888 Posting Maven

i like to listen sometimes.

but mostly i just like to hear myself talk.

jephthah 1,888 Posting Maven

hi and welcome! hope you're finding what you need :) go holla in the forums.

jephthah 1,888 Posting Maven

hi and welcome! hope you're, um... finding what you need?

jephthah 1,888 Posting Maven

hi and welcome! hope you're finding what you need :)

jephthah 1,888 Posting Maven

hi and welcome, islam! hope you're finding what you need :)

dont worry about being new, go post away in C++, plenty of folks will help. its the most active forum here.

jephthah 1,888 Posting Maven

hi and welcome, Yusef! hope you're finding what you need :)

jephthah 1,888 Posting Maven

exiled to CA, hmm?

im sure your neighbors must love the new Texan who thinks CA is the Gulag.

:P


.