jephthah 1,888 Posting Maven

in case it's not clear...

your parsing method will count the opening brace in line 6, but not the closing brace in line 10

jephthah 1,888 Posting Maven

speaking of pedantry, you spelled "poseur" wrong.

jephthah 1,888 Posting Maven

my goodness, did someone pee in your cornflakes?

he ASKED for an optimization, on his otherwise already-working code.

so i PROVIDED one.

you don't like it? fine, go roll your own.


at any rate, i think my example has instructive purposes, even if it's overkill for the project at hand.

jephthah 1,888 Posting Maven

yeah, try developing any sort of cryptographic tool with that mindset.

WaltP commented: OK -- enough. You aren't making your point so drop it. -2
jephthah 1,888 Posting Maven

au contraire, mon frere

try running mine with a line size of 40, and then try running his with the same (change n=40)

mine is about 2x as fast.

and i'm certain the gain will continue to increase as line size increases

jephthah 1,888 Posting Maven

hey i bitched about gotos.

i'll do it again.

jephthah 1,888 Posting Maven

http://www.digitalmars.com/

you have my sympathy.

jephthah 1,888 Posting Maven

no worries.

i've got the .h file if you need it.

and a makefile, too.

jephthah 1,888 Posting Maven

but they're still not random.

jephthah 1,888 Posting Maven

glad you got it :)

jephthah 1,888 Posting Maven

this will be considerably faster if only because it uses just one "printf" statement to display the pyramid.

#include <stdio.h>

void geometric(int number, int *result)
{
    if (number)
    {
        *result += number--;
        geometric(number, result);
    }
}


int main()
{
    char stringNum[3], *pyramid, *pyr_p;
    int numLines, arraysize, i, printNum;

    // request size of "pyramid"
    printf("enter number: ");
    gets(stringNum);
    numLines = atol(stringNum);
    if (numLines<0) return 0;

    // dynamically allocate pyramid array
    arraysize = numLines * numLines + 1;
    geometric((numLines+1), &arraysize);
    pyramid = malloc (arraysize * sizeof(char));
    memset(pyramid,32,arraysize);
    pyr_p = pyramid;

    //develop pyramid pattern
    for (i=1; i<=numLines; i++)
    {
        pyr_p += (numLines-i);
        printNum = i;
        while (printNum)
            *pyr_p++ = 48 + (printNum-- % 10);
        while (++printNum < i)
            *pyr_p++ = 48 + ((printNum+1) % 10);
        *pyr_p++ = '\n';
    }
    *pyr_p = 0;

    //print pyramid pattern to term
    printf("\n%s\n",pyramid);
    free(pyramid);
    return 0;
}
jephthah 1,888 Posting Maven

why the f would anyone think this is a reasonable question for a programming class?

no wonder so many people come out of CSC 101 or whatever hating programming, and not knowing how to do a damn thing.

jephthah 1,888 Posting Maven

uh, did you try this?

C:\> copy file.txt C:\path\to\new\place\
C:\> cd C:\path\to\new\place
C:\path\to\new\place> type file.txt
jephthah 1,888 Posting Maven

here, try this... just remove the comments, change some variable names, sign it and turn it in. trust me, it works. you'll get an "A" for sure.

/* diff - compare files line by line

   Copyright (C) 1988, 1989, 1992, 1993, 1994, 1996, 1998, 2001, 2002,
   2004 Free Software Foundation, Inc.

   This file is part of GNU DIFF.

   GNU DIFF is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   GNU DIFF is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   See the GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with GNU DIFF; see the file COPYING.
   If not, write to the Free Software Foundation,
   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */

#define GDIFF_MAIN
#include "diff.h"
#include "paths.h"
#include <c-stack.h>
#include <dirname.h>
#include <error.h>
#include <exclude.h>
#include <exit.h>
#include <exitfail.h>
#include <file-type.h>
#include <fnmatch.h>
#include <getopt.h>
#include <hard-locale.h>
#include <posixver.h>
#include <prepargs.h>
#include <quotesys.h>
#include <setmode.h>
#include <version-etc.h>
#include <xalloc.h>

#ifndef GUTTER_WIDTH_MINIMUM
# define GUTTER_WIDTH_MINIMUM 3
#endif

struct regexp_list
{
  char *regexps;	/* chars representing disjunction of the regexps */
  size_t len;		/* chars used in `regexps' */
  size_t size;		/* size malloc'ed for `regexps'; 0 if not …
jephthah 1,888 Posting Maven

lol... the first google link comes back here

jephthah 1,888 Posting Maven

what about lithp?

jephthah 1,888 Posting Maven

just because you include the header file doesn't mean you're getting the code. the errors you described earlier sound like you're not linking properly.

the solution depends on your compiler, and how their source code is provided... whether it's in a .dll or a .lib or whatever

jephthah 1,888 Posting Maven

there's no such thing as a random number.

num = rand();

will return a "pseudo-random" number over the interval between 0 and 2^32, depending on your compiler.

not truly random, but i suspect that it will have enough "appearance" of being random for your purposes.

jephthah 1,888 Posting Maven

1) i noticed in your earlier code you were using = when you should have been using ==

2) you also had a do statement without a corresponding while condition. avoid do/while's for this and other reasons. you should stick with "while" loops unless you have compelling reason to use "do/while"

3) you should not be "return"-ing in the "else" statement.

4) you should not attempt to define the end of a function by the appearance of "return"... besides the fact that void types do not return a value, a function can have any number of return statements.

otherwise, this sort of works in a basic sense:

use strict;

my $openCount;
my $closeCount;
my $foundReturn;
my $myCfile;

die "usage: perl $0 <filename>\n" 
    if (!($ARGV[0]));

die "file: <",$ARGV[0],"> does not exist\n" 
    if (! -e ($myCfile = $ARGV[0]));

open(fp,$myCfile);
open(writeme,">output.txt");

print "reading <",$myCfile,"> ...\n";

$openCount = $closeCount = $foundReturn = 0;
while(<fp>)
{
    if ($_ =~  /return/)  {
        print "hey am inside return if\n";
        $foundReturn=1;
    }
    elsif(($_ =~ /^\{/) || ($_ =~ /\{$/)) {
        $openCount++;
        print "openCount1=", $openCount ,"\n";
    }
    elsif(($_ =~ /^\}/) || ($_=~ /\}$/ )) {
        $closeCount++;
        print "closeCount=", $closeCount,"\n";
    }
    if($openCount==$closeCount) {
        print "count is equal\n";
    }
}

you STILL have the problem that if a brace is both preceded and followed by any combination of whitespace, comments, or additional code -- which is a VERY likely prospect -- your counting code will become immediately and irretreivably lost.

for instance:

int main …
jephthah 1,888 Posting Maven

for one thing, you cant put the begin/end of line operators (^ and $) inside parentheses. they must be immediately adjacent to the match operator like this

/^  ...regex...  $/

for another thing, you can't put the LOGICAL OR inside a regex. you need to break it down into separate expressions like this

if (($var =~ /^  ...  $/) || ($var =~ /^ ... $/))
{
    do stuff
}

also, can you ever think of a function that will never match the regex

/return/

perhaps a function like this:

void myStupidFunction (void) 
{  
     printf("hi world!\n");
     foo = bar;
}

finally, you can't guarantee that the open or close braces are ALWAYS going to be either at the beginning or end of a line. that would then fail to find any indented brace that had spurious whitespace afterwards, much less a brace that was preceded and followed by more code. like this:

for (a=1; a<10; a++) {     // only call 9 times!
     myFunction(a); 
}

your method (as I interpret it from the apparent intent of your code) will fail to find the opening brace, and only count the closing brace. thereby getting your counting algorithm hopelessly lost.

jephthah 1,888 Posting Maven

hello Jonnel, welcome to two weeks ago.

instead of a pedantic discussion on your clever use of "while()" .... maybe you can explain where "textcolor()" comes from and how one would implement it on a Win32, linux, unix or os/x platform.

jephthah 1,888 Posting Maven

three problems with your post ^


(1) strcmpi is a Microsoft-specific implementation. it wont work on "real" C.

(2) strcmpi was deprecated as of 2005.

(3) your usage of getch( ) within the loops is irretrievably broken.

what on earth even makes you think that such a construct would work? have you ever written a program to get input from a terminal?

jephthah 1,888 Posting Maven

are you threatening me????

jephthah 1,888 Posting Maven

can some one make this before 19 march 2008.
it is my homework

LOL you kids, i swear

how about you send me $500 to my PayPal account and I'll won't track your IP address and tell your teacher what you're up to..

jephthah 1,888 Posting Maven

You Again??

GTFO

jephthah 1,888 Posting Maven

I have seen your problem & itry to solv it out .

i seriously doubt that.

please help me to rite a sample TSR

how about if i sign your address up with every contact on the ROKSO blacklist, just for being a rude thread hijacker.

start your own thread.

and you better post some code in it or i shall taunt you a second time.

jephthah 1,888 Posting Maven

this is better...

check this out, dude, and see if you understand this.

#include <iostream>
using namespace std;
using std::boolalpha;
using std::cout;
int main ()
{
   bool comparison1, comparison2, comparison3, comparison4, comparison5, comparison6, comparison7, comparison8;
   char comp1[32], comp2[32], comp3[32], comp4[32], comp5[32], comp6[32], comp7[32], comp8[32], equivalence[32];
   
   int x = 4;
   int y = 8;
   int a = 5;
   int b = 6;
   int g = 2;
   int i = 3;
   int j = 7;

   comparison1 = (x >= 5 ) || ( y < 7 );
   comparison2 = !(x < 5 ) && ! ( y >= 7 );
   strcpy(comp1,"(x >= 5 ) || ( y < 7 )");
   strcpy(comp2,"!(x < 5 ) && ! ( y >= 7 )");  
   
   if (comparison1 == comparison2)
	   strcpy(equivalence," is equivalent to ");
   else
	   strcpy(equivalence," is NOT equivalent to ");  
   cout << comp1 << equivalence << comp2 << endl;
   
   comparison3 = (( a != b ) && ( g == 5 ));
   comparison4 = (!(a == b ) || ! ( g != 5 ));  
   strcpy(comp3,"(( a != b ) && ( g == 5 ))");
   strcpy(comp4,"(!(a == b ) || ! ( g != 5 ))");  
   
   if (comparison3 == comparison4)
	   strcpy(equivalence," is equivalent to ");
   else
	   strcpy(equivalence," is NOT equivalent to ");  
   cout << comp3 << equivalence << comp4 << endl;
   
   comparison5 = (x > 8 ) || ( y <= 4 );
   comparison6 = (! ( x <= 8 ) && ( y > 4 ));
   strcpy(comp5,"(x > 8 ) || …
jephthah 1,888 Posting Maven

dang it... that would have been easy enough to include, had i noticed it.....

here it is now...

#include <iostream>
using namespace std;
using std::boolalpha;
using std::cout;
int main ()
{
   bool comparison1, comparison2, comparison3, comparison4, comparison5, comparison6, comparison7, comparison8;
   
   int x = 4;
   int y = 8;
   int a = 5;
   int b = 6;
   int g = 2;
   int i = 3;
   int j = 7;

   comparison1 = (x >= 5 ) || ( y < 7 );
   comparison2 = !(x < 5 ) && ! ( y >= 7 );
   
   if (comparison1 == comparison2)
   {
      cout << "!(x < 5) && !(y >= 7) is equivalent to" 
         << " !((x < 5) || (y >= 7))" 
         << endl;
   }
   else{
      cout << "!(x < 5) && !(y >= 7) is not equivalent to" 
         << " !((x < 5) || (y >= 7))" 
         << endl;
   }
   
   comparison3 = (( a != b ) && ( g == 5 ));
   comparison4 = (!(a == b ) || ! ( g != 5 ));
   
   if (comparison3 == comparison4)
   {
      cout << "!(a = = b) || !(g ! = 5 ) is equivalent to" 
         << "!(a = = b) && ! (g ! = 5 ))" 
         << endl;
   }
   else
   {
      cout << " !(a = = b) || !(g ! = 5 ) is not equivalent to" 
         << "!(a = = b) && ! (g ! = 5 )" 
         << endl;
   }
   
   comparison5 = (x > 8 …
jephthah 1,888 Posting Maven

oh, shit... i just noticed that. i was in such a hurry, all i could do was to get rid of brackets, parentheses, and the redundant type delcarations, so the damn thing would compile and run.

as it was, he only had 5 minutes left to submit, so part-credit is better than no-credit. we didn't have time to debug the rest

feel free to debug the logic. hes gonna have to know how to get through this one way or another before he can pass the class, i reckon....

jephthah 1,888 Posting Maven

contact me tomorrow sometime when you want to try and go over what you were doing wrong. i promise i wont be such a d1ck about it. :P

your bracket problem, its fundamental, and is probably just a simple misconception you have somewhere that needs to be cleared up.

you can submit my cleaned up version of your code. it is all your code, i just removed some extra brackets and parentheses, and a few redundant bool declarations.

it runs, and the logic is all yours. i left that alone.

the output indicates that they are all "equivalent"

[jezebel@localhost cprogs]$ ./a.out
!(x < 5) && !(y >= 7) is equivalent to !((x < 5) || (y >= 7))
!(a = = b) || !(g ! = 5 ) is equivalent to!(a = = b) && ! (g ! = 5 ))
!(x <= 8) && ( y > 4 ) is equivalent to !(x <= 8 || ( y > 4 ))
!(i > 4 ) || ( j <= 6 ) is equivalent to !( i >4 && ( j <= 6))
[jezebel@localhost cprogs]$
jephthah 1,888 Posting Maven

HEY, HERE IT IS. I FIXED A LOT OF ERRORS

NOW IT WORKS... SORT OF.

I DONT THINK THE LOGIC IS EXACTLY RIGHT, BUT IT COMPILES AND RUNS

#include <iostream>
using namespace std;
using std::boolalpha;
using std::cout;
int main ()
{
   bool comparison1, comparison2, comparison3, comparison4, comparison5, comparison6, comparison7, comparison8;
   
   int x = 4;
   int y = 8;
   int a = 5;
   int b = 6;
   int g = 2;
   int i = 3;
   int j = 7;

   comparison1 = (x >= 5 ) || ( y < 7 );
   comparison2 = !(x < 5 ) && ! ( y >= 7 );
   
   if ((!(x < 5) && !(y >= 7)) == (!((x < 5) || (y >= 7))))
   {
      cout << "!(x < 5) && !(y >= 7) is equivalent to" 
         << " !((x < 5) || (y >= 7))" 
         << endl;
   }
   else{
      cout << "!(x < 5) && !(y >= 7) is not equivalent to" 
         << " !((x < 5) || (y >= 7))" 
         << endl;
   }
   
   comparison3 = (( a != b ) && ( g == 5 ));
   comparison4 = (!(a == b ) || ! ( g != 5 ));
   
   if ((!(a == b) || ! (g != 5 )) == (!(a==b ) && (g != 5)))
   {
      cout << "!(a = = b) || !(g ! = 5 ) is equivalent to" 
         << "!(a = = b) && ! (g ! = 5 ))" 
         << endl;
   }
   else
   {
      cout …
jephthah 1,888 Posting Maven

but like i mentioned earlier, you do need to indent your code, and copy and paste code with indention directly here with the code tags.

jephthah 1,888 Posting Maven

look i made a bunch of errors when i started too

(code=cpp)
(code=cpp)

this is how you put code in between the code tags

(/code)
(/code)

jephthah 1,888 Posting Maven

god, dude, im sorry.

i dont mean to make you feel bad

its been a long day

i made a bunch of errors when i started too

:(

jephthah 1,888 Posting Maven

oh no... i just noticed the brackets.

you can not just arbitrary start dropping brackets anywhere you feel like.

how did you ever get this far?


.......... deep breath.


okay. good try with the code tags.

remember:

[opentag=c]
stuff in the middle
[/closetag]

close tag needs a slash "/"

but the code tags do not help much if you dont properly indent your code. can you read what you've written there? how can you ever make sense of anything if it all blurs together in a jumbly way like that?

i hope you use indents when you write code, and that this is just cut-and-paste problems.

when you copy and paste your code in between the [code] tags, be sure to copy it from your editor where you wrote it, along with the indentations.

jephthah 1,888 Posting Maven

your problem boils down to one major defect. you are putting TOO MANY OF ONE TYPE OF PARENTHESIS, WITHOUT HAVING A MATCHING AMOUNT OF THE OTHER TYPE

look.... do you think this is correct?

( ! ( here is a parenthetical expression ) ) ) ) ) ) )

no? why not?

because maybe ive got 2 opening parentheses, and 7 close parentheses? does that look right to you? no? well thats what you're doing.

and thats is why your code isnt working. well, maybe there are additional problems, but we'll never be able to tell until you start tagging your code to make it readable.

i dont know how to explain it any better than this[code=c] tagging your code to make it readable.

i dont know how to explain it any better than this

jephthah 1,888 Posting Maven

you need to end the code with

(/code)

i cant put both set of tags in one post or

the tags disappear and turn the code into highlighted code

like that

jephthah 1,888 Posting Maven

you know it's damn near impossible to read code like that.

is it really too much to ask for you to put the code tags in there? you type right over the instructions everytime you post.

jephthah 1,888 Posting Maven

Sadly, too many people take the "never use goto!" as some sort of silly religious mantra

YOU SHALL PAY FOR YOUR INSOLENCE, BLASPHEMOUR!

but if you can't think of any legitimate reasons to use goto, you're not qualified to tell people never to use it.

actually, i have a confession. ive used GOTOs recently in the context of error handling for hardware drivers, following a convention that was established by National Instrument's source code. i swallowed my distaste because it was rather simple and concise in the way it was structured.... but i didnt want to get into that here.

to see a simple input routine run by GOTOs is just painful. Truly, theres nothing that GOTOs do that cant be done another, equally good and probably better, way. using GOTOs in professional work is usually a sign of either incompetence or laziness, so the last thing people should be teaching students is to use GOTO.

Now when you have the misfortune of inheriting some 5 year old code of 50,000 lines and hundreds of functions, and some fargin bastage has gone and put GOTOs and Globally scoped variables all over the eff-ing place --- it makes you want to hunt down Kernigan and Ritchie and ask them WTF's idea was it to allow GOTO in the first place, even against the advice of many industry professionals.


.

jephthah 1,888 Posting Maven

I kno how to print a static array, but I dont know why I cannot wrap my head around this dynamic array with pointers concept.

oh, whoops. sorry. i missed where you said that this was a dynamic array.

i didnt actually read your code. i still can't see past those big ugly GOTO's

jephthah 1,888 Posting Maven

now here's something that might be of interest to you.

char names[3][32];   // array of 3 names, each being a string of up to 32 chars
int index =0;

...


while (index<3) {

    printf("enter name #%d : ",index);
    scanf("%s",names[index]);

    index++;
}

...

for (index=0; index<3; index++) {

    printf("name #%d : ",name[index]);

}
jephthah 1,888 Posting Maven

any sort of conditional statement is fine ... "while" is a common one to use

so instead of, say, doing this:

A:  printf("enter name : ");
    scanf("%s", gotName);

    ... stuff ...

    if (strcmp(gotName,"quit") == 0)
        goto A;

do something like this:

int isDone = 0;
char gotName[32];

while ( ! isDone)
{
    printf("enter name ");
    scanf("%s", gotName);

    if (strcmp(gotName,"quit") == 0)   
        isDone = 1;
    else 
    {
        ... stuff ...
    }
}

seriously though. im not being facetious. gotos make me ill. the use of gotos should absolutely never be done, unless there is a really, really compelling reason to do so. And I can't think of any.

they should never have been allowed to be included into the language.

other options are using "for" loops and "do/while" loops ... related useful commands include "continue" and "break" which cause the loop to be immediately run again, or immediately broken out from, respectively.

.

jephthah 1,888 Posting Maven

no worries mate.

i'll look at this later tonight. (US Pacific). I'm not especially familiar with GL to rattle off an answer, and I dont have time to dig into it while at work.

jephthah 1,888 Posting Maven

for the love of all that is good and holy, please remove those foul GOTO statements.

the answer is easy enough, but i cant even bear to look at this code as long as there's a GOTO in there.

jephthah 1,888 Posting Maven

yes, using ifdef in that manner is the right way to go.

and <winsock.h> should do it. its based on the BSD unix sockets, so it's pretty similar. there may be slight differences, i dont remember exactly.

http://msdn2.microsoft.com/en-us/library/ms740673%28VS.85%29.aspx

jephthah 1,888 Posting Maven

now if you want to access any element for inspection, just call it like so:

int lowestIdNum = 99;
int lowestStudentIndex= -1;

for (a = 0; a < totalNumOfStudents; a++) 
{
    if (Student[a].id <lowestIdNum )
    {
        lowestIdNum = Student[a].id;
        lowestStudentIndex= a;
    }
}

printf("Student: %s has the lowest ID number (%d)\n",
            Student[lowestStudentIndex].full_name,
            lowestIdNum );
jephthah 1,888 Posting Maven

ive tried and tried and still nothing.
i just dont get it.
how do i copy the line in my struct and copy it as a string...

okay, here's your structure

#
typedef struct {
    int id; 
    char full_name[LEN]; 
    struct {
        unsigned sem_a; 
        unsigned sem_b;
    }grades; 
}Student;

so you need to declare a variable of type student, then fill each of its elements. here's a very basic way that will suffice for illustration:

// declares an array of 10 students
Student myStudents[10];

// make a temp buffer long enough to read each line
char buffer[64];

// declare some temp vars to store data 
// not neccessary, but good for illustration here.
int num, first, second;
char name[32];

//  normally "buffer" would have the string read 
//  into it by fgets() ... for this example I'm just
//  using a simple strcpy( ) to illustrate
strcpy(buffer,"15 JoeSchmoe 95 87");  

// scanf expects data fields to be formatted precisely.
// format variations will cause unexpected results.
// copy the fields into temp variables
scanf(buffer,"%d %s %d %d", &num, name, &first, &second);

// write the fields into the first index of your student array structure
myStudent[0].id = num;
strcpy(myStudent[0].full_name, name);
myStudent[0].grades.sem_a = first;
myStudent[0].grades.sem_b = second;

now your "myStudent" array has its first element filled

you would of course want to use a while loop in which you would repeatedly do an fgets( ) to read the lines, along with an incremental counter to move through each index …

jephthah 1,888 Posting Maven

lol i can't read hebrew

jephthah 1,888 Posting Maven

well, sorry if i offended you with my post.

all i meant was that perhaps you can post some code to help us get started with.

its just hard to guess what exactly you want to do and how you're trying to go about it. i dont really feel like creating a GL app from scratch.

jephthah 1,888 Posting Maven

it isn't "necessarily" always at the first spot.

but the regex should be correct.

post more code. use tags, please[code=c] tags, please