WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

IMO you'd be better off writing something like <*end*> between messages, rather than Ctrl-D in the file. Why would you want someone to enter Ctrl-D anyway?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Every time you type a character in at scanf("%c",); , do you hit an ENTER? Where does that second character go? It gets read with the next scanf() . See this series about why you should not use scanf() for character & string input. Use fgets() instead.

And in your case, you can define a string instead of a single character, use fgets() to read the input (which automatically clears the input buffer -- within reason), and simply look at the first character in the string for your character. Yes, it's a little kludgy, but that's the problem with keyboard input in C unfortunately.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Never use scanf() to read a string (here's why). In your code, if you enter more than 5 characters you are overwriting memory you shouldn't touch.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Not normally, although you can pipe stderr to a file by using 2 in front of the pipe character: prog 2>err.file

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Look up fgets()

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Answer given on another site...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I have this tic tac toe code, it`s almost working, can anybody take a look, I think the only thing wrong is in the else statement in main, but I`m not sure, I think I need to place the checkToWin and checkToBlock functions properly in main

What make you think that? Does it do something wrong? You need to explain the problem you see and not make us guess what's going on.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I believe the program is called lint.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

We don't do homework for people. Most of us already have graduated and don't need the grade. Read the Forum Rules and post an appropriate question and we can help.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

>What is the significance of the following format specifiers:
Relatively low, but they come in handy occasionally.

:twisted: :twisted:

%10s    - Output a minimum of 10 chars, leading spaces
%.10s   - Output up to 10 characters
%-10s   - Output a minimum of 10 chars, trailing spaces
%.15s   - see above
%-15s   - see above
%15.10s  - output up to 10 chars with 5 leading spaces
%-15.10s - output up to 10 chars with 5 trailing spaces

You could have tested it out yourself, you know. Just write a program that tests them:

#include <stdio.h>
#include <string.h>
#define NEXTCOL 38

char *strs      = "ABCDEF";
char *strl      = "ABCDEFGHIJKL";
int   sizesingle= 9;
int   size[][2]= {   3,  3,   -3,  3,    3,  9,   -3,  9,
                     3, -3,    3, -9,   -3, -3,   -3, -9,
                     3, 15,    3,-15,   -3, 15,   -3,-15,
                     0,  0,
                     9,  3,   -9,  3,   -9,  9,   -9, -3,
                    -9, -9,   -9, 15,   -9, -15,   9,  9,
                     9, -9,    9, -3,    9,  15,   9,-15,
                     0,  0,
                    15,  3,   15,  9,   15, -3,   15, -9,
                    15, 15,   15,-15,  -15,  3,  -15,  9,
                   -15, -9,  -15, 15,  -15,-15,  -15, -3,
                    -1,  0
                  };
char buf[20];
                
int main()
{
    int  i = 0;
    int  j;
    
    j = printf("  Short -- %d chars <%s> ", strlen(strs), strs);
    while (j++ < NEXTCOL)  putchar(' ');
    printf("  Long -- %d chars <%s>  \n", strlen(strl), strl);
    printf("\n");
    
    j = sprintf(buf,"%*s", sizesingle, strs);
    j = printf("       %%%3ds (%2d)  <%s> ", sizesingle, j, buf);
    while (j++ < NEXTCOL)  putchar(' ');
    j …
Salem commented: Nice +17
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Please be more specific.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You need a book on databases. Teaching that is beyond the scope of this forum.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

First, format your code.
Second, look up the kbhit() and getch() functions in your compiler documentation.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Open your compiler's IDE
Type the code in you've written
Save the code
Run it and see if it works.

iamthwee commented: Wonderful advice, bravo! +11
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

First off, rewrite the return so it is understandable (i.e. simple). Then explain what you want. Your request makes little sense.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Welcome. While registering, new members are requested to read the Forum Rules and other pertinent information (sticky posts with obvious titles like Read this first) before posting. Did you miss this request during registration?

And in English, after punctuation like , . ? and ! there is always a space so people can understand your post.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

The first time the compiler processes the header, _global_h_included_ is undefined so the header is processed. During this processing, _global_h_included_ is defined.

Each subsequent time the header is processed, _global_h_included_ is already defined, so the rest of the header is skipped thanks to the #ifndef

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I'm wondering where to find what values system() accepts. For example, I want to list the server's OS type. I already did man system, did not find it very useful. And google is returning a lot but nothing relevant.

Type HELP at the command line.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Ok, it just seems strange compared to how easy it is in Java.

It just seems strange that girls have to sit down compared to how boys can just stand. Maybe it's the nature of the beast...
Wondering why an orange and a cumquat aren't the same is a waste of time -- you need to learn and accept the differences. There's always a reason.

Anyway, did you mean 8 characters, because from the docs it seems like the null terminator is not included (and whatever by itself is 8 chars).

No, nine characters. The null terminator is part of the string and must be included in the count.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Right away you shouldn't use:

char name[20];
scanf("%s",&name);

It should be:

char name[20];
scanf("%s",name);

Actually, no it shouldn't. See this.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

If you are in fact Tomm Gunn, thus a guy...

I know for a fact that Narue is female.

Haven't you ever heard of Sybil?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Display each grid you generate and see where the errors occur in the generations.

Are you taking into account that the edged of the grid only have 5 neighbors and not 8?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

i will give you my code:
and try to adopt it on your code

...
void clear_kb(void)
{ char junk[80];
   gets(junk);
}

You should really read the thread you are posting in. You would have learned something about gets()

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I disagree.

1) I don't like the new buttons. They have a retro feel and don't really do it for me. The yellow buttons fit the look of the page IMO.

2) I prefer multiquote rather than Flag to Quote. The former tells me what the button does. The latter tells me very little.

3) I want the Reply without quote back. I for one use it a lot.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I agree with Dave. What I do now is click the CODE tag and add the I -- very pita.

And as for AD's solution, that's fine for him. Many times I'm not on the keyboard constantly and the rat is easier in those cases.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

If you are using turbo C then use getch() not getchar(). Its in the header file conio.h.

Don't listen to dkalite. getch() is not standard, getchar() is.

As for your problem, my crystal ball tells me your problem is on line 75 of your code... :icon_confused:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

ok i have made a calculator using turbo c but it keeps disappearing when i choose the run command can any body help me please

Maybe if you USE CODE TAGS and Format your Code we might be able to help you. But your code is unreadable without formatting.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

And in C for(unsigned i = 0; i < cantidad_frases; i++) is illegal. i must be defined before it is used, not in the for statement.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Also you are not writing C++ code so all your variable definitions need to be at the top of your functions, before any executable statements.

And for us to follow your code, use proper formatting

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Me too.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Why didn't you use CODE TAGs? Information is posted all over this site about CODE tags, like
1) in the Rules you were asked to read when you registered
2) in the text at the top of this forum
3) in the announcement at the top of this forum titled Please use BB Code and Inlinecode tags
4) in the sticky post above titled Read Me: Read This Before Posting
5) any place CODE tags were used, even in responses to your posts
6) Even on the background of the box you actually typed your message in!

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Nothing.
But return (0); or return 0; will exit the program and return 0 to the operating system.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Yes we can help you, but you must post code for us to help with. Read the Rules and the important sticky posts for info.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Since you are using upperCase and lowerCase as character arrays rather than strings, you need to output each value individually.

If you want to use them as a string, you need to remember that as string always ends with \0, so they need to 27 characters long.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Wouldn't it be helpful to us that aren't psychic to actually explain the problem? I assume you are having trouble compiling.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Set a value to 0.
Then when you read a number, subtract 0x30 from it which converts it to a binary digit .
Now multiply value by 10 and add the digit .

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

As requested, Gaiety:

decalre a union with one double value and char array of 8 bytes.
in Little Endian format , always the sign will be MSB.
so take 7th array, and perform AND operation with 1(char) left shifted 7 times.
and return the resultant value.

NOTE: the returned value is not 1 here but is 128 in case of -Ve.
not sure its efficient.

Way too complex for a new programmer...

AND ing with 0X8000000000000000 is good idea but bit wise operations on float value is not valid.

Not true. What is true is ANDing with a float's maintissa or exponent and getting a useful result is difficult to impossible, but the sign bit is a defined bit in a defined location so it's perfectly valid. If I'm wrong, please point (link) me to the rules & explanation.

Please correct me if i am wrong.
i'm too eager to know, other efficient methods.

Done... :icon_wink:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Will some one please help with the topological sort problem. What am I doing wrong? Thanks in advance for your help!!

1) Using a useless BOLD for your question
2) Not using CODE tags
3) Not explaining what your problem is
4) Not telling us about where in your code the problem is

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Put the digits into a char string. When you get a non-number. convert the digits using a function such as atoi() . Copy the operator to another variable.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

0x8000000000000000 is the 'sign bit' of a 64 bit value. AND it with the value you want to check. If TRUE, the sign bit is set.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I usually have to do some work to get something I need. You have to, also.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

:icon_rolleyes: What a bunch of useless responses :icon_rolleyes:
except for Tom's...

Why you don't use void with main() : click here

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

so im sorry waltp.. im just a newbie user here... and i want 2 learn from this website so pls help me not to scold me... alright... again... i've seen you solved many problems here ...my tcher always using getch instead of return 0...what's the difernce...

Then read the Rules and the sticky post with titles that sound important. Easily fixed.

Here's why you should not use getch(): click here.

Here's why your main() is wrong: click here. And return x; is required to properly exit a program.

And no current compilers use clrscr() so your teacher is teaching old, useless techniques.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

how can we use a printf statement without a semicolon???
this was a question asked during an interview of a computer engineering student.

Assuming this was a job interview, I suggest you stay away from any job that asks foolish questions like this. I would not want to work for a company that want it's programmers to use tricks that make code unreadable.

yellowSnow commented: First sensible response to this thread. Exactly what I wanted to say. ;-) +2
kvprajapati commented: Very good suggestion. +6
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Start by doing 1a which is very basic and quite simple. Then start adding the code for 1b. When you get stuck actually coding, we can help you overcome those problems. But you have to code something for us to help with.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

All you do is set valid to false at the beginning, never change it anywhere else in the code.

Think again -- what is the exit condition you need for the while and do-while loops.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

@waltP, what do you mean, guessNumber never changes?

if( quit == false ) { guessNumber = rand()%100 + 1; }

When the game is near its end it changes if player wan'ts to play again.

Sorry. I didn't see that code because it didn't make sense to me at the end, and in that form. It's best at the beginning of the loop in this case.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

How will i convert this binary code"10110111" into decimal value?
I have used the following codes

Did your code work? If not, what happened? What value did you input? What value was output? How can you tell it didn't work?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

It also never gets a new number. The line guessNumber = rand() % 100 + 1; Needs to be inside the loop.