riahc3 50 Â Team Colleague

I think both of you just limit in another array the amount of chars in a char array when I want it to read/write the first letters then when it detects the first space (" ") and when it detects a "\0", it should just to the next line again the first space and again a "\0" until it reaches EOF...

riahc3 50 Â Team Colleague

Hey

I have a file named filetext.txt with the text:

One word
Two words
Three words
Four words

and the program should read this filetext.txt and output to another file called filecopied.txt this text:

One
Two
Three
Four

I have this so far:

#include <assert.h>
#include <complex.h>
#include <ctype.h>
#include <errno.h>
#include <fenv.h>
#include <float.h>
#include <inttypes.h>
#include <iso646.h>
#include <limits.h>
#include <locale.h>
#include <math.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>



int main()
{
    FILE *filetext
    FILE *filecopied;
    char text[50];

    filetext=fopen("filetext.txt","r");
    filecopied=fopen("filecopied.txt","w");

    if ((filetext==NULL) || (filecopied==NULL))
        {
            printf ("A file cannot be opened");
            return 1;
        }

       // fgets(text,50,filetext);
        //sscanf("%s ",text);
        sscanf("%s\n",fgets(text,50,filetext));
        //sscanf("%s\n",fgets(text,50,filetext));
        fprintf(filecopied,"%s",text);
        fclose(filecopied);
        fclose(filetext);
        return 0;
}

It doesnt write anything to the file so how can I solve it? Id like to use fgets, fprintf, and sscanf. Thanks.

riahc3 50 Â Team Colleague

Gaiety I did not understand what you mean/said so here is the code translated:

#include <assert.h>
#include <complex.h>
#include <ctype.h>
#include <errno.h>
#include <fenv.h>
#include <float.h>
#include <inttypes.h>
#include <iso646.h>
#include <limits.h>
#include <locale.h>
#include <math.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>




int main()
{
    FILE *filepairs; //This pointer points to the file that contains the "this is line 1" etc 
    FILE *filecopied; //This pointer points to where the lines will be copied to
    char text[50]; //A string array
    int i=1; //a counter

/* Opening the files */
    filepairs=fopen("filepairs.txt","r");
    filecopied=fopen("filecopied.txt","w");


    if ((filepairs==NULL) || (filecopied==NULL))
    {
        printf ("One of the files cannot be opened!");
        return 1;
    }
    else
    {
        while (fgets(text,sizeof text,filepairs))
        {
            fgets(text,50,filepairs);
            if (i % 2 == 0)
            {
                fprintf(filecopied,"%s\n",text);
            }
            if (filepairs!=NULL)
            {
                i=i+1;
            }
        }
        fclose(filepairs);
        fclose(filecopied);
        return 0;
    }
}

I hope this clears it up for everyone. Thanks to everyone for trying to help out :)

riahc3 50 Â Team Colleague

Change

do{
            fgets(texto,50,archivopar);
            if (i % 2 == 0)
            {
                fprintf(archivocopiado,"%s\n",texto);
            }
            if (archivopar!=EOF)
            {
                i=i+1;
            }
        }while(archivopar!=EOF);

to

while(fgets(texto,sizeof texto,archivopar))
         {
            if (i % 2 == 0)
            {
                fprintf(archivocopiado,"%s\n",texto);
            }
            if (archivopar!=EOF)
            {
                i=i+1;
            }
        }

...more or less.

Thanks but now its just weird lol....

It copies in the file only the forth line and the seventh line...

riahc3 50 Â Team Colleague

Hey

I have a text file (1.txt) with the lines:

This is line 1
This is line 2
This is line 3
This is line 4
This is line 5

and Im trying to read all the pair lines from that file and write them to another text file called 2.txt which would result in this:

This is line 2
This is line 4

My code works but the problem is at the end it runs into a infinite loop and the result is

This is line 2
This is line 4
This is line 5
This is line 5
This is line 5
This is line 5
This is line 5
This is line 5
This is......

until I manually stop the program. I imagine there is something wrong with my EOF loop and/or the length I set. Also maybe the program doesnt know it should jump to the next line when it reads a /n or something. The variables are in spanish but I THINK they could be understood. If not, Ill translate

#include <assert.h>
#include <complex.h>
#include <ctype.h>
#include <errno.h>
#include <fenv.h>
#include <float.h>
#include <inttypes.h>
#include <iso646.h>
#include <limits.h>
#include <locale.h>
#include <math.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>

int main()
{
    FILE *archivopar;
    FILE *archivocopiado;
    char …
riahc3 50 Â Team Colleague

I rather use the VS 2008 complier myself but AFAIK it is NOT standard (eg. it will comply exactly in another IDE/complier/etc).

I dont give a shit about gcc. Also, I rather use gcc, besides the standard, is because the rest of people are using gcc so if there is a problem, it will be a common problem.

riahc3 50 Â Team Colleague

Then any of the popular compilers will meet that condition. You will not find a C89 compiler that is noticeably better than the rest.

Yet VS 2008's C compiler is different than a standard C compiler.

Please forgive me for the offensive remark. I will remember that your humor mechanism is in need of repair and avoid similar remarks in the future. :icon_rolleyes:

Please forgive me for hurting your feelings. I did not know you get so emotional over the truth.

riahc3 50 Â Team Colleague

I am not qualified to answer that since I have not done it. But I know it can be done, so you can probably find instructions with a web search.

OK....

Every C compiler I know of in regular use conforms to C89, and C89 is still the defacto standard for C. The only C compiler I know of that conforms completely to C99 is Comeau. Gcc does not yet conform to C99, and unless they have fixed it, many of the custom extensions conflict with equivalent C99 features and make conformance either very fragile or impossible. It is in a better state than VC, where Microsoft has said they have no plans for conforming to C99, but partial conformance is still a portability issue.

Exactly. I want the best complier that is compatible with C89. I have no intrest in C99.

Picky picky. ;) I still think Code::Blocks is your best bet, but I also think Visual C++ is the best IDE hands down.

Well if im "picky picky", then I invite you to go ahead and buy the complier for me and donate to me.

If I could get Visual C++ to use the gcc complier and the gdb debugger, that would be great.

riahc3 50 Â Team Colleague

Most IDEs, including Visual Studio, can be configured to use a different compiler.

Really? Then how can I set in VS 2008 to use gcc and gdb as the debugger (including the rest of the minigw compilation which is the port of gcc to windows)

I am wondering why you think gcc is the best C compiler.

Simply because it conforms to the regular standards of C and it is free.

I would say the best is Comeau because it conforms to the latest standards of both C and C++. The only problems with Comeau are it is not free, and it is only a front-end compiler, so it is not as easy as install and go.

(I have never heard of the Comeau complier)
1: It is not free
2: It is not the easiest to install so that automatically makes it lose points

riahc3 50 Â Team Colleague

I concur - Codeblocks is good.

But I use Eclipse far more often as it has support for other languages that I use (for work and for play). So for me, it's a "one-stop" shop as far as an IDE is concerned. And it's not too bad to configure for C development. I use the MinGW toolchain in combination with gdb. The debugger has some minor issues that should hopefully be sorted out soon - but generally speaking the set up works well enough.

Eclipse simply sucks for C. Period. Configuring it is difficult.

riahc3 50 Â Team Colleague

Hey

I know gcc is problably the best natural complier for C but Im looking for a IDE. I cant use Visual Studio 2008 (which Id like to) as it uses it own compiler. I was using wx-dev (I believe it is called like that) and it is pretty good. I was told about Eclipse but it just sucks because it is confusing (Java; Figures). The debugger also needs to be compatibile with gdb.

Thanks

riahc3 50 Â Team Colleague

I actually contacted the author of Cheese and he said he be willing to do it but he doesnt understand enough of Windows to be able to port it himself so he needs some help...

Any takers?

riahc3 50 Â Team Colleague

there are runtime environments like cygwin, which gives you the
source code level compability. But you have to compile the entire
source code targert as win32 binary.
http://www.cygwin.com/

but there are supported under some constraints.You need some
little change in you're code base.

A bit more explanation please :)

I install Cygwin then I (in Cygwin, hoping it has a GUI frontend) comply it (Cheese's source) as a Win32 binary? And thats it?

riahc3 50 Â Team Colleague

Hey

I was wondering how I could port and comply a Linux application to run it under Windows?

The application I want to port is Cheese.

riahc3 50 Â Team Colleague

you shouldn't be cd'ing in a shell script to do backups in my opinion so that should be irrelevant.

Not sure what you ment by cd'ing....I havent used cd in anything Ive said.

riahc3 50 Â Team Colleague

.... you have a long road ahead of you :)

Rome wasnt built in a day right? Even though I have to get Rome done in alot less days....

Take your pick

sk@sk:~$ pwd
/home/wheel/sk
sk@sk:~$ echo ${PWD}
/home/wheel/sk

AFAIK, pwd is just a function that returns the current path and $PWD is just a variable that changes each time Im at a new path.

Correct? So the best way (IMO) would be just simply using path...

riahc3 50 Â Team Colleague

As far as your concept for builing the directories -- yes, that is how you would go about it. However ls prints out a lot of crap you don't need for this so you would be better off using find /src/dir -type d to make that directories with mkdir -p and then use find /src/dir -type f to get the files.

I believe /src/dir is the current directory so I would have to change it; Is there any variable in Linux that shows the current directory? Could I maybe use pwd?

riahc3 50 Â Team Colleague

Ok well build a file index of your source directories and destination directories. Then build a list of source/dest files that do not exist in either folders and delete/add them as necessary. For files that do exist in both directories you should use an md5sum and filesize check depending on how careful you want to be. Collision rates are very low (unless malicious and intentional) for md5sums so you could probably get away with just do that.

You could use ls and parse the columns, or use du or stat :

root@svn:/root/backup# du -b backup.sh | sed 's/\([0-9]*\)\(.*\)/\1/'
4252

Just because the size is the same doesn't mean that it has not changed so also compare the md5 stamp:

root@svn:/root/backup# md5sum backup.sh  | sed 's/\([a-Z0-9]*\)\(.*\)/\1/'
241cca25e509409c1fbd6f1d46ec94e6

Now just automate all of that and you're good to go!

Thank you for helping :)

Lets analize everything.
du lists with details everything in the current folder, -b showing it in bytes and sed cuts off all the chars listed. That I understand.

md5sum would actually show me the md5 of backup.sh right? Not the actual files in the backed up file/folder/etc. And why would I cut off those chars if md5 includes letters and numbers?

Also reexplain please the part about "build a file index of your source directories and destination directories. Then build a list of source/dest files that do not exist in either folders and delete/add them as necessary."

would I have to do something …

riahc3 50 Â Team Colleague

Yeah .. look at the rsync source for ideas :)

I rather not "rip" code from another utility.

Id just like to make this using a shell script. Please no more comments suggesting rsync. Thank you :)

sknake commented: fair enough, i wont badger you anymore :P +9
riahc3 50 Â Team Colleague

Why don't you just use rsync? This is a significant undertaking when the wheel has already been invented.

Thanks but I rather use a self made shell script. Any tips?

riahc3 50 Â Team Colleague

Hey

Ive been asked (and I may add this to my system as well) to make a shell script that backups to all files in x location to another location in z. The thing is that the backup must only be made if one file has been changed. Example:

/x contains:

a (1 byte)
b (1 byte)
c (1 byte)

/y contains:

nothing

Ill put this script into CRON's file and everytime (say 3) it will execute. 3 arrives and there is nothing in /y and it will copy all files in /x to /y. To compensate space I think a good idea (this I will do to my script for my system) is gzip it all up. Anyways the current state right now is.

/x contains:

a (1 byte)
b (1 byte)
c (1 byte)

/y contains:

a (1 byte)
b (1 byte)
c (1 byte)

Again 3 arrives and /y is the same as /x so nothing changes and nothing happens. But now, I open c in /x and type something inside now it is:

/x contains:

a (1 byte)
b (1 byte)
c (2 bytes)

This changes it so now when the script excutes at 3 it has to delete everything in /y and rewrite it all over again (regardless that the other files havent changed).

How do I do this? I imagine something …

riahc3 50 Â Team Colleague

Im using wxDev-C++ 6.10.2 using the default GCC compiler

riahc3 50 Â Team Colleague

Hmm MessageBox(0,"Message body", "Message title", MB_OK ); doesnt work. Ive included windows.h but nothing. It complies with no errors and no warnings but just (blank program) tells me press any key to continue...

riahc3 50 Â Team Colleague

Damn it is a shame that there is no standard function for it and it is only avaliable in Windows. Thanks anyhow :)

riahc3 50 Â Team Colleague

Hey

I was wondering how to generate a Windows popup in C. I mean by "Windows popup" as in (for example) when you do a net send message to a PC, a simple Windows popup comes up on the PC you sent the message to with the message. How can I generate one of those Windows popup messages in C? Tried looking for something on Google but only things like .NET, C++, and such come up. Thanks.

riahc3 50 Â Team Colleague

It's called code completion/class browsing in wxDev-C++. See Tools/Editor Options/Class browsing.

It is enabled and it doesnt seem to work. Could you write a quick code example which works for you so I can test it out? I thought my example worked but maybe it doesnt.

riahc3 50 Â Team Colleague

Hey

In VS, you can in a struct do:

struct test{
int tes;
}tt;

then when I put tt., it would display the all fields in a tooltip which in this case would display tes. Is "IntelliSense" (I know it is not called that) in wxDev-C++?

riahc3 50 Â Team Colleague

I still don't get why you bother adding zero.

Because I needed 0.

riahc3 50 Â Team Colleague

So if this were a pack of cards, player1 would choose a card, and the others would be dealt a card from the remaining deck.

Think of it in these terms,
- shuffle the deck
- find card (and remove it)
- deal card (from the top of the deck, and remove it)

Can't be a card because you know there are only 1-12 cards. This number can be infinite.

And yes I already thought of the array but I wanted to check if there was a easier/better way. I guess I'll just do it with another array comparing the array which stores the numbers.

riahc3 50 Â Team Colleague

Have you tried storing the used random numbers and then searching that list when you need another?

Obviously, this is the solution the problem is how to implant it.
Do I make another array storing all the numbers?
And/or how?
lets say we have player[n]
player[1] says 1 (because he typed it in)
player[2] gets a generated number of 3 (because the generator returned him that number)
player[3] gets a generated number of 2 (fine again)
player[4] gets a generated number of 1; No. The generator must regenerate another number because this number has been said by one of the players before him. This time 3. Again no because player[2] said 3. Another generation this time 0. Next player...
Next player[5] gets generated 0. Again. 1. Again. 3. Again. 1. Again. 3. Again 2. Again. 0. Again. 2. Again. 3. Again. 4. FINALLY gets a good number

Thats bascially what I want to do. Im just not sure how to do it. Im not asking for the actual code just ideas on how to do it.

riahc3 50 Â Team Colleague

n=((int) ((1+(3*numberofplayers)) * (rand() / (1.0 + RAND_MAX))) + 0) ;

Works pretty well :) numberofplayers is a global variable so I dont need to pass it.


Thank you very much to everyone who has helped out.

riahc3 50 Â Team Colleague

Kinda important so bumping up...

riahc3 50 Â Team Colleague

>>Take a C course in some center in your city. WILL help you out...
I think a C course is a waste of time(even when you've got some to spare). I've learned more from the Internet and Daniweb than I have from my course.

Even if you have no idea about programming like this guy does?

Obviously, he doesnt like programming either so a course with indivdual (sp?) help will help him.

riahc3 50 Â Team Colleague

BTW use wvDev-C++; Much better IDE.

riahc3 50 Â Team Colleague

How can you put p=o?

P is a integer. Do you even know what a integer is?

riahc3 50 Â Team Colleague

Hmm I think what Im looking for is:

n=((int) ((1+(3*numberofplayers)) * (rand() / (1.0 + RAND_MAX))) + 0) ;
riahc3 50 Â Team Colleague

Hmm Im not sure if I should start another topic since this is a different topic but:

Right now I was using:

n=rand()%(3*numberofplayers+1);

How can I adapt that to

n=((int) (5 * (rand() / (1.0 + RAND_MAX))) + 0) ;

[s]Maybe this:

n=((int) (5 * (rand() / ((1.0+3*numberofplayers) + RAND_MAX))) + 0) ;

???[/s]

Nope, doesnt seem to work...

riahc3 50 Â Team Colleague

There you go, a program to print a balanced checkbook

Well I learnt something from this thread

printf(
        "CHECKBOOK\n"
        "=========\n"
        "    ^\n"
        );

Had no idea you could do that in C.

Salem commented: :) at least someone got something out of it +32
riahc3 50 Â Team Colleague

My suggestion:

Take a C course in some center in your city. WILL help you out...

riahc3 50 Â Team Colleague

This complys:

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

void fnlogincheck();
int main(int argc,char**argv)
{
    system("cls");
    fnlogincheck();
    return 0;
}

void fnlogincheck()
{
char *pcloginid[3]={"user1","user2","user3"};
char *pcpwd[3]={"Potato","Tomato","Turnip"};
int l,p,i,c;
char login[5];
char password[6];
printf("\n\n\n\n\t\tEmployee Information System\n");
printf("\t\t===========================\n\n");
printf("\t\tLogin Screen\n");
printf("\t\t============\n");
printf("\n\t\tEnter User Id\t: ");
scanf("%s",&login);
printf("\n\t\tEnter Password\t: ");
scanf("%s",&password);



//l=strcmp(&loginid[i], login);
//p=!strcmp(&pwd[i],password);

password[c]= password[6];
printf("*");
for(c=0;c<=6;c++)

{
if( l=p)
    printf("LOGIN ACCEPTED");
else
    printf("LOGIN DENIED");

exit;
}
}

But again, What the fuck are you trying to do with this code???

riahc3 50 Â Team Colleague

WOW....

I have no idea what you are trying to do but you are WAY over your head.
1: Learn to use "tab"
2: password[c]= password[6] with no ; at the end? (Thatll problably solve 99% of the complying errors
3:
What the fuck is this:

{
l=strcmp(&loginid[i], login);
p=!strcmp(&pwd[i],password);
for(i=o,i<=3,i++)
}

{

Personally I think you come from another programming language that should either stick to it or reread from C manuals.

riahc3 50 Â Team Colleague

From tests, it seems range just tells you how many numbers it generates.

If I put range 5, it generates 5 numbers which are 0,1,2,3 and 4.

Is this correct?

riahc3 50 Â Team Colleague

Thanks WaltP but I dont get your function too well. Sorry.

I understand that "Start" is the number (including itself) I want to start from. But I fail to see range as in the first example the range is -2 the actual numbers till I want it but the next example is double+1 the actual number.

riahc3 50 Â Team Colleague

Hey

The title is a bit confusing so Ill explain.

I have a function that returns random values from 0-4 for the computer (which has numberofplayers). Lets say number of players is 2. One is me and the other is the PC. I (myself thru a scanf and I being player 1) set my value for 2. How can I create some kind of for/do/if/etc that keeps generating numbers until player 2 has a number differerent than player 1 (me)? Obviously the 0-4 range and the number of player changes depending on the options I set.


If someone needs more explaining or some kind of code example, please go ahead and post.

riahc3 50 Â Team Colleague

Hey

Im already generating numbers correctly from 0 to MAX_INT. But Id like to know how can I change that range (including negetive numbers)

And while already on the subject, why does this code only generate numbers in the VERY high 90s?

int main()
{
    int array[100];
    srand(time(0));
    gen(array);
    return 0;
}

void gen (int *array)
{
    int i;
    for (i=0;i<=100;i++)
    {
        array[i]=rand()%100;
    }
}
riahc3 50 Â Team Colleague

I thought you ment to ask you guys nicely.

riahc3 50 Â Team Colleague

The correct answer is a variable....

It can be changed to 5, 10, 100000000000....depends.

riahc3 50 Â Team Colleague

Lets say people say

1,3,4,6,9,10,44

And the correct answer is 5. How do I calculate the closest number to 5? Thanks.

riahc3 50 Â Team Colleague

I already asked nicely.


And about learning the language instead of the compiler, I dont care much as programming is not something I want to dominate and dont see it as my possible future career.

riahc3 50 Â Team Colleague

>>Ive been taught C this way.
You were taught wrong for most compilers.

The newest version of the C standards will allow you to declare objects anywhere you want, just like the C++ standards has done all along. The problem is you need to find a compiler that is new enough to implement that standard. VC++2008 also will not compile that code.

Still noone has answer another question...

Is there a way like in wxDev-C++ to change the complier from the VS one to the gcc one?