jephthah 1,888 Posting Maven

on further review, your question really doesnt make a lot of sense.

what are you asking?

jephthah 1,888 Posting Maven

char myCharacter = 'A';
printf("%c = %d",myCharacter,myCharacter);

jephthah 1,888 Posting Maven

^ just EDITED, to include the File Pointer "pFile"... dont forget that :P

jephthah 1,888 Posting Maven

your STATE variable (it seems) is an array of integers, correct?

fputs expects a pointer to a character string, and you're using fprintf wrong.

look up the definition of predefined functions in any code reference, when they dont behave like you think they should

http://www.cplusplus.com/reference/clibrary/cstdio/fprintf.html

not knowing anything about your STATE variable, or how it's scoped, i'd suggest you try something like this: fprintf(pFile, "State[%d] = %d\n",STATE_SONAR_0+i,State[STATE_SONAR_0+i]); .

jephthah 1,888 Posting Maven

medoyem i just realized you are not the original poster. i made a mistake. sorry for the confusion.

oceanaut you cant just throw a few hundred lines of code out and hope Giapetto's elves come along and fix it for you.

what is your problem with the code? besides the 38 silly errors as mdoyem pointed out. perhaps you should start by fixing the obvious compile errors. then come back with specific questions.

jephthah 1,888 Posting Maven

Dude, it is just programming, I mean take it easy :p

yeah, you're right: i don't really care.

enjoy.

jephthah 1,888 Posting Maven

what does what mean?


.

jephthah 1,888 Posting Maven

Thanks alot for ur reply,,,,,but when I tried to run this code a 38 errors have occured

so what it seems to me that you're saying, is that you don't understand anything about the code you posted because, i assume, you copied it from someone/somewhere else?

if i'm wrong, then accept my apologies, and continue by explaining

what errors are you getting
what have you already tried to fix said errors
what particular function are you having trouble with?

jephthah 1,888 Posting Maven

the answer to your specific question: Y will equal X will equal the char 'A'.

putchar does not modify the character in any way, it only displays it, and moves the stdout file pointer to the next position.

---

and yeah, i can cipher out *what* that FOR statement does well enough, what i dont understand is *why* anyone would would code it this way. it's almost as if it were deliberately confusing.

if it were just an isolated occurance, i might try and work with it. but it is part of a function that is called from within another loop in the caller that is likewise conditional upon input from stdin. (the other c=getchar() call in main)

the whole thing is a godawful mess. kill it now and start over. see my previous post on how you should do this. last night i wrote the entire program from scratch, to accept input from either stdin or a file, in about 30 minutes, although it's not fully debugged. if it takes you 5 hours to do the same, you'll be all the better for it.

But hey, you don't have to take my word for it. If you think your program is worth saving, maybe you can find someone who'll take the time to sort through it. I can't/won't. I don't have the patience.

the only way i can see is to start over and do it in a more "traditional" way with …

jephthah 1,888 Posting Maven
jephthah 1,888 Posting Maven

go to zigbee.

become a member

join their forums.

discuss zigbee questions there.

when you have C-language questions, come back here

:)

jephthah 1,888 Posting Maven

use tags, please[code=c] tags, please

jephthah 1,888 Posting Maven
jephthah 1,888 Posting Maven

man, look at this FOR statement for(bracket_char=0;c!=EOF && c!='\n' && c!=B_CLOSE && bracket_char<B_CHAR_MAX;bracket_char++, c=getchar()) arrrgh.

must. resist. stabbing. eyes. with. pencil.

sorry man, i can't debug this for you. and by "can't", I mean "won't" ... i mean, your code is full of this type of convoluted constructions. for me to fix your code, would require me to think in this obfuscated manner

I'm going to assume you inhereted this mess from your friend whom you are trying to help with this assignment. Your job now is to be a good friend and tell him to start this whole thing over from scratch.

SIMPLY PUT, here is probably the most basic method of how you could (and should, IMO) do it::

get your input all at once and store it before attempting to work on it.

search input for opening and closing brackets to find your tags.

if the tag is an opening tag (no slash '/' ), PUSH the tag onto a single stack

if tag is a closing tag (has leading slash '/' ) POP the a tag from the stack and compare it to the closing tag just read. the POP'ed tag should be the opening mate of the closing tag, so should match (minus the slash) ... if they dont, you have a mismatched tag error.

if all tags have matched and you've reached the end of the input, your stack should be empty ... if it's not empty, then you …

jephthah 1,888 Posting Maven

yeah, sorry im so damn picky, but see i just spent ~30 minutes getting to the point where i could read your code.

i havent even started to debug it.

I'm by no means a software guru. perhaps others here can cipher out the intent of your code and it's errors just looking at it.

but if i cant read it, i just come to a mental stop. maybe its an emotional hangup, i dunno. but it is what it is.

good luck

jephthah 1,888 Posting Maven

I think I missed something in for loop, and I've just edited the "cleaned up" code i posted in #21, above.

I admit i have neither compiled nor run either your original code or my cleaned up code. so, don't assume anything.

but Ive got to go now. im supposed to be doing work at my job

:P

hopefully someone else will come along and pick up where ive left off.

ill stop by later tonight (US PDT)

jephthah 1,888 Posting Maven

another problem, IMO, is all that stuff you got slammed into the FOR statement, esp. the one in "push( )".

mabye it's correct and working... but damned if it doesn't make it hard to read. i don't even really even want to try and debug it.

consider breaking it out into the body of your FOR loop.

people will not pay you for clever, obfuscated code. people will pay you for readable, understandable code that is easy for others to maintain.

jephthah 1,888 Posting Maven

okay dude.

i just spent the time cleaning up your code, and taking out all those spurious semicolons. you still probably have some problems, but at least we can find them now.

some of what i did was preference (like whether the opening bracket '{' of a block is directly after the statement or on its own line)

but most of what i did is foundational stuff for readability. writing readable code is one of the most important things you can do. the key is "maintainability"

because even if your code is wrong, at least someone can work with it. otherwise, it will just get thrown away.

now check it out:

#include <stdio.h>
#define B_OPEN '<'
#define B_CLOSE '>'
#define BRACKET_MAX 10
#define B_CHAR_MAX 7

char bracket[BRACKET_MAX][B_CHAR_MAX];
char bracket_off [BRACKET_MAX][B_CHAR_MAX]; //new
int diagnosis;
signed char bracket_nr;
signed char bracket_nr_off;


/****************Function Prototypes*****************/
int push (void);
int writetags (void);




/****************Main Function********************/
int main (void)
{
    extern int diagnosis;
    extern signed char bracket_nr;
    extern signed char off_bracket_nr;
    char c;
    
    bracket_nr=-1;
    diagnosis=0;
    
    while((c=getchar())!=EOF && c!='\n') 
    {         
        if(c==B_OPEN) 
            diagnosis=push();    
         
        switch (diagnosis)
        {
            case -3:
                 printf("infinate bracket.\n");
                 break;
            case -5:
                printf("Too Large Bracket.\n");
                break;
            case -7:
                printf("Too many bracket.\n");
                break;              
        }
            
        if (diagnosis < 0)
            break;     
    }
    
    if (diagnosis==0)
        printf("No brackets.\n");

    else if (diagnosis > 0)
    {
        printf("You have written %d brackets; they are:\n",diagnosis);
        writetags();

        if (diagnosis%2==0)
            printf("You have entered correct number of brackets in the HTML statement\n");

        else if (diagnosis%2!=0)
            printf("You have entered incorrect number of brackets in the …
jephthah 1,888 Posting Maven

why do you have a semicolon ';' after all your end brackets '}'

these do not belong. in some cases it wont hurt, but in other cases it will seriously F- up your logic.

this right here may be the source of most if not all your problem

jephthah 1,888 Posting Maven

yeah, i hate to be a whiny biatch, but i cant really read your code with all the indentations either.

im at work right now, so i dont have time to sort through it by inspection, if i can't easily read it.. i probably will be too tired/busy to get on it when i come home.

its not your fault, really, your TABS probably look just fine on your end. but here, each TAB converts into 8 spaces... perhaps you notice all the lines of code wrapping?

i get around this by using my editor's "Replace All" function to replace every TAB character with 3 spaces before posting it here.

now see, all this time i spent whining about formatting, i could have been inspecting your code! :P


EDIT:

i just peeked at your code some more, and i gotta say you got WAY too much stuff going on inside your FOR statements. put that stuff inside the loop. you're asking for logical and control errors by trying to crush 5 commands into just the FOR statement alone.

and in addition to converting TABS to spaces, you need to line up your indentions better. the sloppiness adds to the unreadability.

not trying to be a bish about it. but i just dont have time to edit your code for formatting.


.

jephthah 1,888 Posting Maven

well, speaking only for myself, it wasn't so my code posts that made me go "eww"

:-P

jephthah 1,888 Posting Maven

eh, fair enough.

i never said it was bulletproof. it's far too simplistic to be anywhere near that, yet still too complicated for some of the "hello world" type programs here.

perhaps my real problem is that the poster forced me to review some of my earliest posts here, making me think "eww. did i really post that?"

i miss your chainsaw, by the way


.

jephthah 1,888 Posting Maven

The code presented by Jepthah will not correctly vaildate 12..3 or 12.b.rr.3 and the like

awesome first post, dude.... to a thread that was dead for 2 1/2 months.

did you have a better solution?


.

jephthah 1,888 Posting Maven

It has to do with human perception, not compiler equivalences.

It's the same as teaching children to dial nine-eleven in case of emergency. Many can't find the 11 button and don't have the knowledge how to correct it.

so youre saying the difference between NULL and '0' is meaningful only because people are stupid?

because otherwise, you're admitting it's just a style point. but to be honest, I do like the style... NULL makes code pretty.

In fact, this thread has convinced me to start using it more consistently.


.

jephthah 1,888 Posting Maven

dont worry, you wont remember it much of it. i didnt remember much of it, other than the basic principle that floating point numbers have finite amount of accuracy and precision.

i had to look up those details i had learned once and mostly forgotten. i was writing ^ and ^^ out as much for myself as for anyone else.

just try to understand it, and you'll at least remember where to go look it up next time. (IEEE standards)

jephthah 1,888 Posting Maven

i have a confession to make

im an electrical engineer, not a programmer, so maybe I'm missing the subtleties...

but ASCII 0x00 sure looks like a big fat zero to me.

at any rate, I can almost as easily type 'NULL' as I can '0' ... the extra keystrokes will be worth it if it pleases the aesthetics of the stylistic purists.


for the record:

NATIONAL INSTRUMENTS' CVI
<stdlib.h>

#ifndef NULL
#define NULL 0
#endif

MICROSOFT MSVC
<stdlib.h>

/* Define NULL pointer value */
#ifndef NULL
#ifdef __cplusplus
#define NULL    0
#else
#define NULL    ((void *)0)
#endif
#endif

GNU C COMPILER (GCC)
<system.h>

/* Define a generic NULL if one hasn't already been defined.  */
#ifndef NULL
#define NULL 0
#endif
jephthah 1,888 Posting Maven

the answer is:

IF they are asking crazy ambiguous questions like this, AND you don't have the slightest clue as to how to reasonably answer it, THEN this is not a place you want to work.

you should put that down as your answer.

Fo' Serious.

jephthah 1,888 Posting Maven

sounds like those stupid interview questions hipsters at places like Microsoft think its cool to ask

...

anyhow, my first thought was temperature.

but i like the height of the sun better.

jephthah 1,888 Posting Maven

i need to declare it outside

so pick up your laptop and go declare it outside. just make sure it's not raining, or that you have a good awning at least.

sorry. :P

actually i dont understand your question. what are you trying to declare "outside" ? and why do you think a for loop works one way in C++ but differently in C? what do you think it should be doing, that it's not?

jephthah 1,888 Posting Maven

okay damn. you got me there...

(*shuffles a bit, kicks at the dirt*)

but at this point, I will insert into the specification document: "NOT INTENDED TO WORK WITH CTRL-D or CTRL-Z"

Stupendous Man flies again!

w00t

jephthah 1,888 Posting Maven

hah.. check this out.

change your line of code that prints the sum to print out 10 decimal places

printf("The total is now %.10f\n", total);

then recompile and run:

C:\Users\Owner\Desktop\rob work\scratch>float.exe

 This program will ask you to enter 4 numbers.

Enter a number: 26.2
The total is now 26.2000007629

there it is: 23 bits of precision, plus one "implied" bit, rounded to the nearest number. "up" in this case.


last thing. i probably shouldnt get into, but just for completeness:

your floating point binary value actually looks like this:

0 10000011 10100011001100110011010
|  |______|  |_____________________|                                          
|        |                          |
|        |                          |____"normalized" mantissa
|        |
|        |_____exponent = 2^4
|
|_____sign bit (positive)

look up IEEE 754 bit fields if you really want to go there.


.

jephthah 1,888 Posting Maven

this is a common "problem" with floating point numbers: most floating point representations of decimal values are not exact numbers.. they are approximations.

here's the short answer:

single-precision floating point value (type float) is represented by 24 bits in the mantissa, and 8 bits in the exponent. this is in Base 2 number system. so any fractional power of 2 (or sum of such numbers) is easily represented, but numbers not a sum of fractional powers of two must be rounded at some point.

ask yourself how much precision do you need? is 4 or 5 significant digits enough for you? much of the time in general use it is, so use it and round off with he format specifiers for printf()

printf("%5.03f \n",myFloat);

will give you 26.200 printed to the screen. if you need more precision than 6 digits, use type double.

now the long answer:

think of how we (with our human base 10 counting) have "problems" with numbers like 1/3 and 1/6 and 1/12. its not a lot of fun to take 0.333333333 to infinite places, so we eventually round off at some point.

the "rules" for computing floating point numbers is covered by IEEE Std 754. here is an over-simplified example:

your number 26 is represented by 11010 as an integer... but as a float, it is represented by 11010.00000000000000000, where the "." is the "binary point". if you wanted to represent 26.5 that's easy to do …

jephthah 1,888 Posting Maven

Ancient Dragon is right. Aia, what you're talking about is an "allowed" definition of NULL. not the required definition.

What is NULL and how is it #defined?

As a matter of style, many programmers prefer not to have unadorned 0's scattered through their programs. Therefore, the preprocessor macro NULL is #defined (by <stdio.h> or <stddef.h>) with the value 0, possibly cast to (void *). A programmer who wishes to make explicit the distinction between 0 the integer and 0 the null pointer constant can then use NULL whenever a null pointer is required.

Using NULL is a stylistic convention only; the preprocessor turns NULL back into 0 which is then recognized by the compiler, in pointer contexts, as before. In particular, a cast may still be necessary before NULL (as before 0) in a function call argument. The table under question 5.2 above applies for NULL as well as 0 (an unadorned NULL is equivalent to an unadorned 0.

References: K&R1 Sec. 5.4 pp. 97-8
K&R2 Sec. 5.4 p. 102
ANSI Sec. 4.1.5, Sec. 3.2.2.3
ISO Sec. 7.1.6, Sec. 6.2.2.3
Rationale Sec. 4.1.5
H&S Sec. 5.3.2 p. 122, Sec. 11.1 p. 292

...

Nevertheless, ANSI C allows the alternate definition #define NULL ((void *)0) for NULL. Besides potentially helping incorrect programs to work (but only on machines with homogeneous pointers, thus questionably valid assistance), this definition may catch programs which use NULL incorrectly (e.g. when the ASCII NUL character was …

jephthah 1,888 Posting Maven

Considering that it takes only one key press to cause it to lock up in an infinite loop, that's a rather optimistic opinion.

Not to mention accessing undefined data if the entered filename is shorter than 4 characters.

wait a minute... i don't believe that's the case. did you find these bugs by running it, or did you just determine this by inspection?

because i can neither cause it to enter an infinite loop, nor does it misbehave for file entry less than 4 chars. it works exactly as it should.

so why ya gotta be a hater? :P


.

jephthah 1,888 Posting Maven

baah.

it was 2am... :P

my point was to try and make it so obviously NOT his own work that he got busted for cheating.

not that anything i did was especially clever or noteworthy --- just that if this kid cant figure out how to programmatically divide by 1024 or multiply by 8... I'd just love to see his face and listen to his stammering when called into the office to explain how "his" program works.

jephthah 1,888 Posting Maven

I am asking for a program which is return in C language

I'm the giver and you're the receiver. copy it directly into your assignment and hand it in.

then come back and tell me how high your grade was. i'm certain you will get an "A"

#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <errno.h>
#include <time.h>
#include <math.h>


#define MAX_FILENAME_LEN    256


int main()
{
   char filename[MAX_FILENAME_LEN], quitstring[5], *ptr;
   struct stat filestats;
   time_t filetime;
   size_t length;
   off_t filesize;
   int stop=0, power, i;

   do
   {
      printf("\nenter filename, or \"quit\" to exit: ");
      if (fgets(filename,MAX_FILENAME_LEN,stdin) == 0)
         continue;

      length=strlen(filename);
      filename[--length] = 0;      // chomp newline

      for (i=0; i<4; i++)         // test for "quit"
         quitstring[i] = tolower(filename[i]);
      quitstring[4]=0;
      if (strcmp(quitstring,"quit") == 0)
      {
         stop = 1;
         continue;
      }

      errno=0;
      if (stat(filename, &filestats) < 0)
      {
         printf(" -- FILE <%s>: %s\n",filename,strerror(errno));
         continue;
      }

      filetime = filestats.st_mtime;
      filesize = filestats.st_size;

      if (filesize/pow(2,20)>1)   //mega
         power=20;
      else                   //kilo
         power=10;

      printf("\n -- FILE: <%s>\n",filename);
      printf("    DATE: last modified %s",
               asctime(localtime(&filetime)));
      printf("    SIZE: %ld Bytes (%5.03f %s, %ld bits)\n",
               filesize,
               (float)filesize/(float)pow(2,power),
               (power>10)?"MB":"KB",
               filesize*8);
      printf("    XMIT: %dh %2dm %2ds <- 30kbps modem\n",
            filesize/10800000,filesize/180000%60,filesize/3000%60);
      printf("          %dh %2dm %2ds <- 1.5Mbps DSL\n",
            filesize/540000000,filesize/9000000%60,filesize/150000%60);
      printf("          %dh %2dm %2ds <- 8.0Mbps Broadband\n",
            filesize/2800000000,filesize/48000000%60,filesize/800000%60);

   } while (!stop);

   return 0;
}
jephthah 1,888 Posting Maven

^ thank you. i was concerned that i was losing my own reading comprehension skills.

jephthah 1,888 Posting Maven

i've become kind of confused as to what it is you are trying to do.

jephthah 1,888 Posting Maven

yeah, because as we all know, Napoleon loved to make puns in English.

...

and hey challenging dude. apologies that we're not all just peeing our pants with delight over the prospect of taking your "challenge"

now here's a challenge for YOU. Locate the "search" button on this site. your challenging homework has only been discussed about 100 times

.

VernonDozier commented: Ha Ha +2
jephthah 1,888 Posting Maven

there once was a man from Nantucket

jephthah 1,888 Posting Maven

yeah, um, i think I'm gonna have to ask you to come in again this Saturday.

jephthah 1,888 Posting Maven

maybe he wants to take already non-portable code and render it completely unusable?

jephthah 1,888 Posting Maven

you people are funny

jephthah 1,888 Posting Maven

i think this is the guy who insisted C++ code was C.

so it just makes sense that he puts his assembly code here as well.

jephthah 1,888 Posting Maven

don't make the array global. declare it in main.


i also think you've got a typo in the function name ... it's "pthread_create". you probably figured that out i'm sure, but just in case...


.

jephthah 1,888 Posting Maven

since no one has come out and said it, i guess i will:

you should avoid using OS-specific libraries such as <conio.h>. this only works with (some) MSFT Windows systems.

your code will never be portable using such libraries.

but, if you dont care, then i guess i dont either.

jephthah 1,888 Posting Maven

you could, of course, just use the format modifiers that go with printf()

ex. printf("%20s",myText); prints the char string "myText" in a 20-character wide field, left justified, padding unused characters with whitespace.

while printf("%-20s",myText); does the same thing except the text is right-justified.

you are responsible for ensuring that the length of "myText" does not exceed the length of the specified field.


.

jephthah 1,888 Posting Maven

Hello Tah.

please excuse Narue's brusqueness. her chainsaw needs oiling.

Now I have made for you a handy program to use in situations just like the one that you are looking for:

#include <stdio.h>

int main ()
{
    printf("hello world!\n");
    return 0;
}

please feel free to cut and paste into a file, rename it as your own, and turn it in!

simple as that.

of course, you can even add your own additional functionality to "spice it up", as they say out here in the industry.... but only if you feel sufficiently motivated. The program will certainly work as it is.

Cheers, and a wonderful day to you sir!

jephthah 1,888 Posting Maven

silly mortal, you doubt my powers?

watch me battle my way through pedantic digressions about the dangers of pseudo-randomness and the evils of scanf, while flying by the seat of my pants deep into the lair of non-error-checked command line input. all in the name of clarity i say!

whoops... here comes Naure

*ahem* now if you'll excuse me, i believe i have other um... threads to rescue.

Aia commented: Hehe. Stupendous man saves the moment once again. +7
jephthah 1,888 Posting Maven

I can assure you that no one over here will prevent you from doing so.

i might.