jephthah 1,888 Posting Maven

oh, i just re-read your last post.

the problem is not with TCP/IP.

the problem is that you need to take the values that you get from the server, and rewrite them to a file with HTML tags.

maaann....

if you can write a server and a client, what you're asking is CHILDS PLAY... ;)

i mean, really...

"fopen"
a bunch of "fprintf"
"fclose"

and you're done.

jephthah 1,888 Posting Maven

yeah, i know.... this account came free with a lvl 70 orc mage i bought on EBay.

:(

Ezzaral commented: You win this thread. +19
Nick Evan commented: Best reply ever. +15
jephthah 1,888 Posting Maven

ah, i see now. there were deleted posts i never saw.

dont mind me, im still figuring this site out.

jephthah 1,888 Posting Maven

maybe i'm missing something, but thats a pretty tame post to get banned for.

i guess you guys aren't used to the wandering StormFront douchebags.....


.

jephthah 1,888 Posting Maven

narue has already given you the answer.

i'm not telling you anything she hasn't already. but maybe i can break it down for you into easy-to-chew bites.


1 -- create a new array.
2 -- start indexing existing array at the first element
3 -- if the existing element does not exist within the new array,
-- 3a -- then copy the existing element to the new array
4 -- move to the next existing array element and repeat at (3)


there are other ways to do it, but it just does not get any more simple than this.


.

jephthah 1,888 Posting Maven

the short answer is: you can't.

the long answer is: you can, but only if all fields are consistently the same width, and there's never any variations in the numbers of fields or their sizes.

in which case, a solution can be where you'll use "fopen" to read, "fgets" to get each line, a string comparison such as "strstr" or "strtok" to find the field in question, a counter to track the position of where you want to change, then "fseek" to re-navigate back to the location in question, and "fwrite" to replace the text.

there's plenty of caveats and assumptions to consider, but if the number, size and position of your fields are immutable, you can take a stab at it and see what happens.

jephthah 1,888 Posting Maven

he only had 36 posts, but somehow i feel as if he will be missed.

jephthah 1,888 Posting Maven

Oh, look.... a Creation vs. Evolution internet smackdown where technologically-minded evolutionists gang up on a few bold (if slightly misguided) proponents of ID/creation science

... and it immediately jumps to 12+ pages in just over a month?


has this ever happened before???


.

jephthah 1,888 Posting Maven

i dont get it.

is this funny?

or is the OP making an account-suicide attempt?

jephthah 1,888 Posting Maven

did this guy get banned for this post?

i mean, yeah it's pretty godawful stupid, but still....

jephthah 1,888 Posting Maven

Maybe the US shouldn't be responsible for feeding people in Africa. After all, Americans pay taxes to the US government, not Africans.

i admire your complete lack of social responsibility.

it must be nice to be able to so neatly view the world in stark black and white terms ..... babies born on one side of a line starve to death. babies born on the other get food.

i wonder though.... will you be first in line at the dole when your family runs out of food in an economic crisis?


.

jephthah 1,888 Posting Maven

You should get all of the facts and form your own unbiased opinion.

man that's too much work. i just want you to give me the answer.

and will you code my senior design project for me? I'll send you the specs. what's your email?

Mindlessly following one group or another is silly.

yainorite? tell that to 6000 years of recorded human history.

jephthah 1,888 Posting Maven

software testing is an easy area to get into. not something you'd want to do long term, necessarily, but one you can def. work your way up from.

jephthah 1,888 Posting Maven

some people think section 11.1 of the Google Docs TOS is the harbinger of the End of Days.

other people say that's just mostly-meaningless legalese for Google to cover their own arses.

then the first group says that the second group has drank the Mountain View kool-aid.

the second group then accuses the first of being Microsoft monkeyboy toolbags.

so who should I believe? which team should i join? do i need to bring my poleaxe, or will weapons be provided?

jephthah 1,888 Posting Maven

an intellectual is just someone whose education level exceeds their abilities.

jephthah 1,888 Posting Maven

C++ is a superset of C. that website covers C++ and C. the referenced <stdio.h> library is standard C.

hey... wait a minute. if you're the best jew since jc, shouldnt you be omniscient?

jephthah 1,888 Posting Maven

if you use it will highlight your C syntax and make it vaguely readable. and if if you also used whitespace to properly indent your code blocks, then we could really read it.

as it sits right now, it just gives me a headache to look at it.

since i can't (won't) read it, i'll just ask the obvious question. are you using TCP or UDP?[code=c] it will highlight your C syntax and make it vaguely readable. and if if you also used whitespace to properly indent your code blocks, then we could really read it.

as it sits right now, it just gives me a headache to look at it.

since i can't (won't) read it, i'll just ask the obvious question. are you using TCP or UDP?

jephthah 1,888 Posting Maven

okay, then you do this:

(1) open the file using "fopen".
(2) use a while loop to read each line into a string buffer using "fgets" until a NULL is returned.
(3) when fgets returns a NULL, it means there are no more lines. the last line read will still be in your string buffer.

"fopen" and "fgets" are widely-used commands from the <stdio.h> standard library. you will find tons of examples on the various online references. here is a good one: http://www.cplusplus.com/reference/clibrary/cstdio/fgets.html

jephthah 1,888 Posting Maven

sup dawg i herd you like to read, so we put some files in your files so you can read while you read

....

naw serosly, what are you saying?? are you saying you want to read the last LINE from your file?

is that it?


.

jephthah 1,888 Posting Maven
void main (void)
{
Crypt Key[26];
analyze(key);
}

one small problem you're going to have is that you're capitalizing your variable declaration, but lowercasing the argument.

you also need to consider whether or not you're going to modify the structure you pass to your function. if so, then you need to use the 'address of' operator (&) to pass the structure, and use the dereference operators (->) to assign new values to the pointed elements of the structure.

jephthah 1,888 Posting Maven

^ his question is totally valid here. you, on the other hand, are not.

jephthah 1,888 Posting Maven

oh good lord

[/carlfacepalm]

jephthah 1,888 Posting Maven

ah, interesting. i havent used Solaris since the early 2000's. i guess i forgot a lot about it.

jephthah 1,888 Posting Maven

and you will, of course, need to change the prototype of your function to match....

jephthah 1,888 Posting Maven

i dont believe you can make pointers to structure elements like that. you should pass a pointer to the entire structure into the function:

pthread_cond_wait(&key);

then in the function, you can modify/access the elements like this

(*key).mutex = whatever;

or using the shorthand method (IMO, the preferred method)

key->mutex = whatever;

.

jephthah 1,888 Posting Maven

well, as he said, it's too basic for him to spend his time on, and its something he needs urgently.

jephthah 1,888 Posting Maven

^ ah, yeah, i just found that, too. R.STILTSKIN is right, i believe.

you are missing the header file

#include <errno.h>

so... let me (re)learn the lesson: bugs are in user code, not compilers.
[/carlfacepalm]


.

jephthah 1,888 Posting Maven

man, are you STILL using chatspeak?

have you considered just cutting your losses now, and creating a new account?

jephthah 1,888 Posting Maven

this particular EBUSY error was the subject of some bug fixes in GCC a few years ago. are you using an older version of GCC that might still have this bug? seems unlikely, but....

anyhow, not trying to blow you off, but since this is not standard C and it may be compiler related, you might get a quicker and more detailed response if you also try asking at GCC's forums.

jephthah 1,888 Posting Maven

how about you take a look at the basics of calendar time functions in the time.h library, take a stab at it yourself, and then come back and ask specific questions.

http://www.gnu.org/software/libtool/manual/libc/Calendar-Time.html#Calendar-Time

because people here will generally NOT do your work for you. as you already found out in your earlier misguided attempt to plagiarize java code.

jephthah 1,888 Posting Maven

Thanks for the code. But the main point here is to store each column values in the file in different arrays coz i have to use those stored array values further in the program. Since i need to store all the values in different arrays which are here in this case separated by a ",".

well... maybe if you would learn how to ask questions properly, you would have titled your question "using arrays" and asked how to index arrays, rather than ask how to use strtok().

i don't know, i'm just sayin'


.

jephthah 1,888 Posting Maven

sounds like the program is working correctly.

review the file that you think is being sent, versus the file that is actually being sent.

i believe there you will find the source of your confusion.

jephthah 1,888 Posting Maven

have you even tried running it?

you run the server on one computer. run the client on another.

specify the port that the server will use by passing the port number as an argument to the executable. see code for example

if (argc != 2)     /* Test for correct number of arguments */
    {
        fprintf(stderr, "Usage:  %s <Server Port>\n", argv[0]);
        exit(1);
    }

    echoServPort = atoi(argv[1]);  /* First arg:  local port */

don't use a reserved port number. pick something greater than 1000 and you should be safe

for the client, send the Server IP, Command, and Port # as arguments to the executable. see the code for example.

if ((argc < 3) || (argc > 4))    /* Test for correct number of arguments */
    {
       fprintf(stderr, "Usage: %s <Server IP> <Echo Word> [<Echo Port>]\n",
               argv[0]);
       exit(1);
    }
jephthah 1,888 Posting Maven

i haven't tested it, but it looks right.

so, what's your question? didnt the site you downloaded the programs from give you some instructions?

jephthah 1,888 Posting Maven

Apparently I don't know usage of malloc

welcome to Daniweb. i'd say of all the people who come in here asking questions that have malloc() somewhere in their code, 90% of them don't have any real concept of how to use it properly. But you're one of the lucky ones: admitting you're powerless is the First Step. now you can stop the abuse cycle, and start the recovery process.

As I know segmentation fault occurs when I try to an unallowed/unallocated space in memory.

then why are you arguing with NARUE about your use of uninitialized pointers?

jephthah 1,888 Posting Maven

since you apparently don't know how to use malloc without mangling it, i suggested you use

char stringblock[MAX_NUM_LINES][MAX_LINE_LEN];

and you replied

I don't know what will be the values of MAX_NUM_LINES and MAX_LINE_LEN values before I read the file and changing these values is not possible after run time I think.

no, of course you cant change them at runtime. so since you dont know what the values are, use ridiculously high values that will cover any possible values. for instance

#define MAX_LINE_LEN     2024
#define MAX_NUM_LINES     512

memory is cheap. what's 1 Meg of memory when you've likely got 1 Gig of RAM? it's better than broken code full of memory leaks because so many programmers have no clue how to properly allocate dynamic memory.

but, really ... go on and use malloc to shoot yourself in the foot. i'm just sticking around for this:

In fact it is 2nd case.
Also if you [Narue] have a big experience then you should know it is not a big deal that people can correct you. If you are uncomfortable with that using forums is not suitable for you. I'm not saying I am an expert but you are wrong about what you've written in previous post. Technically speaking, I initialize and reinitiaize str pointer with every word I read from file. It is not a char pointer array it is just a char pointer. After that I make comparison or whatever I need. At least I know …

jephthah 1,888 Posting Maven

this snippet does no error checking, and is full of assumptions, but I'm posting it here so you get an idea of how strtok() could work.

//get subsequent lines into a char buffer
while (fgets(line,MAX_LINE_LEN,file_ptr))
{
   // tokenize the first item by comma delimiter
   line_ptr = strtok(line,",");

   while(line_ptr != NULL)
   {
      // if there's a decimal point, assume token is float (double)
      if (strstr(line_ptr,"."))
         floatArray[floatIndex++] = atof(line_ptr);

      // otherwise, it's asssumed to be an integer
      else
         intArray[intIndex++] = atol(line_ptr);
         
      // tokenize subsequent items by comma delimiter
      line_ptr = strtok(NULL,",");
      
   }
}
jephthah 1,888 Posting Maven

I did a project a while back and as the grading TA insist on it compiling on Solaris. I have a 0 for a perfectly working project.

its not working if it won't compile

This was a project for a networking class. The project wanted us to establish a TCP and a UDP connection (using Berkeley Socket) and send and receive strings.

unix sockets ... #include <sys/socket.h>
windows .... #include <winsock.h>

I'm not going to post my code here.

okay, then don't expect much help here

I believe in open source programming

then why so much hate for Solaris??? :(

If you want to see my program to help me out let me know your email address and I'll send to code to you.

nah, i get enough email already.

jephthah 1,888 Posting Maven

I'm not saying to not ask questions.... but to ask the right way to get the answers that will be meaningful.

i understand where you are coming from because I've been there myself.

the problem is you're trying to implement the whole shebang all at once and you're paralysed by a non working implementation that you don't know where to begin to debug.

start small, instead. implement one single function and get it to work. then another. then think about how to construct the framework or shell, and how to insert the functionality into that.

(one problem i'm having is I can't access your source code, so i can't relook at your code. i could see it last night at home, but now your webserver is either taking too long to respond, or i've got firewall issues at my work.)

jephthah 1,888 Posting Maven

your problems are so widespread and fundamental, it's not reasonable for me to even try and debug it. this is not a simple fix. to be blunt, you are attempting to take on too complex of a project (for your skill level) at one time.

theres no way to help you at this point, short of rewriting your code and handing it back to you, which would be a lot of effort for us, and no learning opportunity for you.

redefine the scope of your project, and break it into little pieces. do one thing at one time. get that one thing to work right. then as you understand what you are doing, you can expand from there to incorporate more.

you cant just jump into a project with 100 moving parts, and have no clue how many are broken at any given time. narrow your focus down to working on one piece at at time. this forum will help you as you have specific questions.

jephthah 1,888 Posting Maven

hey dude,

i want you to quit posting the same question in repeated threads. what is this, the third one now?

jephthah 1,888 Posting Maven

please stop double posting your question.

you will not get twice the number of answers. you will, in all likelihood, get fewer answers because people find double posters to be annoying.

jephthah 1,888 Posting Maven

first off, theresabsolutely no reason to use MALLOC() here, all youre doing is adding more confusion.

secondly, if you do use MALLOC(), then you need a corresponding FREE() . the fact that youre not using either FREE() or REALLOC() tells me that you dont know what you're doing, and should stay the heck away from dynamic memory allocation until you learn the basics.

now to answer your question:

since you're trying to find the occurance of a string, you should use the standard string library function STRSTR(), since that's precisely what it's designed to do.

you could also look into STRTOK() if you want a more elegant solution, although it might be harder to understand how to use properly.

jephthah 1,888 Posting Maven

here you go amegahed. i tried to be thorough and fault-tolerant, yet clear. see if it makes sense:

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

#define MAX_LINE_LEN    80

int parseResult(char * filename, unsigned lineNumber, double * result);


int main()
{
   double value;

   if (parseResult("myDataLog.txt", 4, &value))
      printf("found result = %3.2f\n", value);

   else
      printf("result not found\n");



   return 0;
}

////////////////////   parseResult   /////////////////////////
//
// reads file and looks for the string "result" on
// the specified line number and ignores previous lines.
// passes back result as double floating point value,
// or returns a zero if failed to find the "result" string
//
// input:  string : filename to open and read
//         unsigned int : line number where result is expected
//
// output: pointer to double : passes back value of 'result'
//
// return: int result 0 = fail, 1 = success
//
// notes:  if function fails, value pointed to by result
//         will not be modified.
//
// warns:  invalid characters (not including whitespace) located
//         between "resul7" and value will cause the function
//         to appear to pass, but pass back the value 0.00 as the
//         result.
//


int parseResult(char * filename, unsigned lineNumber, double * result)
{
   FILE   *filePtr;
   char   buffer[MAX_LINE_LEN], *buffPtr, lastChar;
   int    lineCount = 1;  // indexing first line as line #1

   filePtr = fopen(filename,"r");

   if (filePtr == NULL)
   {
      perror("parseResult");
      return 0;   // fail
   }

   // ASSUMPTION! will not look beyond specified lineNumber
   while (lineCount <= lineNumber)
   {
      buffer[0] …
jephthah 1,888 Posting Maven

nm

jephthah 1,888 Posting Maven

actually i hadn't seen the wiki page. do you think the Linux Coding Style document is unheard of? .... but interesting though that you would point me to the wiki, which supports my point:

Steve McConnell ... the Hungarian naming convention is no longer in widespread use

Bjarne Stroustrup -- No I don't recommend 'Hungarian'.... [it] is completely unsuitable for a language that supports generic programming and object-oriented programming ... [it] simply complicates and minimizes abstraction

the one guy on there who attempts to support it, is merely quoted as describing what the creator of the hungarian notation was *trying* to accomplish.

ANYHOW...

take your obscure coding style to some hacker forum. don't confuse beginners with sloppy, broken code and outmoded coding practices that were discarded in the 1980s.

jephthah 1,888 Posting Maven

The naming convention is hungarian notation names are prefixed with their type

These are both industry standard

in your imagination, maybe. this is an antiquated notation developed by some guy at microsoft in the 70's. even it's proponents agree it's no longer popular, and it's critics are less kind:

Encoding the type of a function into the name (so-called "Hungarian Notation") is brain damaged - the compiler knows the types anyway and can check those, and it only confuses the programmer. No wonder Microsoft makes buggy programs.
-- Linus Torvalds
http://lxr.linux.no/linux/Documentation/CodingStyle


TRUE and FALSE are defined in /usr/include/stdbool.h in the UNIX environment

this is a new feature in C99 and is not industry standard. at the least you need to include stdbool.h. but the whole thing begs the question of how many assumptions you are making about the people who post questions on this website.

I am new here and I am not sure of the strictness of adhering to ANSI standards

since practically the entire industrialized world (except maybe India) adheres to ANSI standard I would say 100%

One can always just return 0 or 1 or define TRUE FALSE in their code if this wont compile on their machine

or you could just post compilable code.

Defining char * as PSZ simplifies reading of code

only if one is, as Linus Torvalds puts it, "brain-damaged"


while (szBuffer == ' ' && szBuffer != 0) i++;
will increment....

jephthah 1,888 Posting Maven

instead of using malloc() (or realloc) poorly.... might i suggest sticking with the tried and true:

char stringblock[MAX_NUM_LINES][MAX_LINE_LEN];

because i'm fairly certain you're not doing an embedded application that is limited for RAM.

but mangling malloc() like you're doing will certainly find the limits of your computer memory after you fill it full of leaks.

jephthah 1,888 Posting Maven

damn, that's a confusing mess if i ever saw one. your naming conventions are unhelpful, to say the least. are you telling us that "int GetLine()" returns TRUE if failed? really?

and, anyhow, are TRUE and FALSE part of the standard C? would you like to explain where they are defined?

why do you post something that has obscure typedefs? whats the purpose of renaming "char *" anyhow?

what's the point of having MAX_LINE_LEN+1, since you don't ever use the unmodified MAX_LINE_LEN in the first place? this will break whenever you try to read the maximum length.

and WTF is the point of the second conditional in this??

while (szBuffer[i] == ' ' && szBuffer[i] != 0)

Finally, your example does nothing to help the poster to answer their question or understand the fundamental concepts.

if you're going to throw code at someone, at least make it concise, coherent, and relevant to the problem. Giving someone a length of rope to go hang themselves with is not "help"

jephthah 1,888 Posting Maven

^ egads. you just walled off 25K of memory for ... what?