Shankye 36 Junior Poster

Copying multiple files into one??

may be cat command you are saying abt?

Shankye 36 Junior Poster

Narue posted just b4 me .. U scan lk tht and later remove the first char (,) or else you can scan a single char and discard that char ..

Shankye 36 Junior Poster

String ends at space so it wont scan countinued name after space..

fscanf(pt,"%d %[^,]s ",&num,surname);
        fgetc(pt);
        fscanf(pt,"%[^\n]s",name);
Shankye 36 Junior Poster

If want sm help to start up ..
use a counter and start counting with the first word, when SPACE detected word ends so temperoraly tht word has longest length store that length in a variable thn start counting length for next word, Compare word length for both.
Depending on the result store the MAX length and corresponding word .. Repeat for all words...
So Get started .. and post your code for any help

Shankye 36 Junior Poster

Post your code .. We will help to solve probs ..

Shankye 36 Junior Poster

wooww Cool ..
and portable too ;-)

Shankye 36 Junior Poster

To count the alphabets we need respective counters.
we have array to keep count of alphabets.
so array[0] keeps count of 'A' whose ASCII value is 65
array[1] keeps count of 'B; whose ASCII value is 66 and so on

by subtracting 'A' from current char we get index of the array and increment perticular counter..
But it has some portibility issue as explained by expert on that thread..
Hopes its clear..
If any doubt ask i'll get to help

Shankye 36 Junior Poster

ya but u have the other way too..
Which that above program u have a shorter way to do that without using switch case or if else..

http://www.daniweb.com/code/snippet329277.html

Shankye 36 Junior Poster

Lol Rofl

Shankye 36 Junior Poster
Shankye 36 Junior Poster

Oh i dint knew that ..

Shankye 36 Junior Poster

oh thanks for info..
Our sir also said left and right values but it confuses a bit, Location and read givens more meaning (and CUTE as you said ;-))

Shankye 36 Junior Poster

use a for loop with a count start with i=1 thn have a MAX value ..
inside loop go on printing count (i) numbers of stars
U will get this

*
**
***
****
....

Shankye 36 Junior Poster

pointer is not initialized ..
Following code ay help ..

#define MAX 100

data first;
data *fp;

first.name = malloc(MAX);

fp = &first;

scanf("%s",first.name);
printf("fp is %s\n",fp->name);
Shankye 36 Junior Poster

You want single instruction ???
I dont think thr are any such instructions which can calculate number of occurances..

But you want a program to calculate it

Count alphabets

Shankye 36 Junior Poster

Location Value

and another is RValue which is Read value..

Shankye 36 Junior Poster

Change datatype of exam, classtanding and total to float as they will hold decimal digits ..

float exam,classtanding,total;

/* Use your code to scan the data, What you wrote in above prog is correct itseems */
/* do calculation */

exams = ((prelim+midterm+semifinals+finals)/4)* 0.6;
classstanding = (quizzes*.05)+(assignments*.15)+(project*.15)+(attendance*.5);
total=exam+classstanding ;

/* print your results */
printf(" Total = %f",total);

Hope its clear..
If not ask your doubts

Shankye 36 Junior Poster

See i dont think there are any problems till 34th line ..
Now tell me how you going to calculate grades using those values mathematically than only i can help you to code it..

Shankye 36 Junior Poster

If problem solved please mark it solved

Shankye 36 Junior Poster

What is this compute you using at 48 and 55th line??
And where you printing your marks calculated ??
If im not wrong you not initialized grade and still using for calculation, you 'll get garbage values

Shankye 36 Junior Poster

Post what all you have ..
How you going to calc grade using percentage thn anyone 'll help you

Shankye 36 Junior Poster

You can start with linus torvalds original linux with is small and easy to understand .. and later you can go on adding few features to that.. Google you can download those codes for free ..

Shankye 36 Junior Poster

Im not understanding what you doing on line 37 ..

I think on line 21 u must remove * ..
strlen takes address, using redirection * u get value at that address ..
so u may change that and check..
Try removing * and check ..

Shankye 36 Junior Poster

ok ..
May i know what type of portability issue with ch-'A' ?

I am not new to C but im doing electronic and Communication engineering so know less about C programming .. Its just hobbie..

Shankye 36 Junior Poster

It counts upper lower and digits in a file ..

Shankye 36 Junior Poster

Hey tht snake game is really cool ..
u may be interested in these too

http://bit.ly/iefllI

http://bit.ly/bDNGap

Shankye 36 Junior Poster

U want to count number of Capital small alphabets and numbers??
If so here is piece of code may help u ..

Assuming Capha, Salpha and num arrays decaired and initialized and fs is source FILE..

while( (ch=getch(fs) != EOF)
{
       if(isupper(ch))
              Capha[ch -'A'] += 1;
       else if(islower(ch))
              Sapha[ch -'a'] += 1;
       else if(isdigit(ch))
              num[ch -'0'] += 1;
}

isupper() , islower and isdigit() functions are in ctype.h you have to include it google about function if want more info ..
Here you will scan a char from file and check whether it is a UpperCase LowerCase or
numeric .. thn using arrays we keeping track of number of counts..
Hope its clear

Shankye 36 Junior Poster

Is it a C program ??????????????????????
Post in Java discussion thread ..

Shankye 36 Junior Poster

Reading others code code is a good way to learn but if you code by yourself you 'll get to learn lots of things ..

I coded a similar program ..
Al you need is ...

// Big while loop 
int direction;
while(1)
{
              if(khbit())
              {
                 //program which returns key, may be like 0 for Up 1 for down 2 n 3 so on
                 direction = getKeyPressed();                  
                 // Mechanism which sets direction of snake
              }
            KeepMovingSnake();
}
Shankye 36 Junior Poster

OMG!!
what actually you are trying to do???

Shankye 36 Junior Poster

Is this you talking about??

while( (ch=getchar())!="\n" && i < MAX_SIZE)
{
          input[i] = ch;
          i++;
}
input[i] = "\0";
Shankye 36 Junior Poster

Ya.. now your program must works fine ..

Shankye 36 Junior Poster

oh ok .. Thanks

Shankye 36 Junior Poster

Oopss sorry new to this place ..

Shankye 36 Junior Poster

There are many ways by which u can copy files ..
copying FILE *fs to *ft ...

while( (ch = getc(fs)) != EOF)  
    {  
        putc(ch,ft);  
    }
Shankye 36 Junior Poster

He mean ..

#include <iostream>
using namespace std;

int main(){
long long num =1;
int i; 

for (i=1; i <=20; i++)
{
    num *=i;
    cout<< i << " * ";
}

cout << "=" << num << endl ;
system("pause");
	return 0;
}
Fbody commented: Not mean. I actually follow the forum rules. -1
Shankye 36 Junior Poster

how flushing stdin causes contents of output stream to be flushed????
It worked fine many times for me ..

Shankye 36 Junior Poster

U can use fflush(stdin) also ..

Shankye 36 Junior Poster

Whats your error???
Answer not correct?

Use a larger data type ..
instead of

int num=1;

try

long num=1;

or

long long num=1;
Shankye 36 Junior Poster

Check with Dev-C++ .. Worked fine for me ..

Shankye 36 Junior Poster

U can add current directory to $PATH
PATH=$PATH:.

Shankye 36 Junior Poster

U using older borland compiler may be ..
It worked totally fine @ me ..
I compiled in Dev-C++ it worked fine but not working in borland ..

Shankye 36 Junior Poster

I dont have clear idea but write() function, may be it writes in binary mode so may be thats why text editors complaining ..

Shankye 36 Junior Poster

Ya dude ..
Break your program into functions..
and post part which is erroneous ..
Thanks for link Walt ..

Shankye 36 Junior Poster

Anyone testing going here?????

May be this is what you wanteed

int menu();

int main()
{
      while(1)
      {
         switch( menu() )
         {
          case 1 : FirstFunction();
            break;
          case 2 : SecondFunction();
            break;
           ..
           ..
           ..
          default: printf("Wrong Choice\n");
           break;
         }
      }
}

int menu()
  {
        int opc;
        printf("What u want to do?\n");
        printf("1. smthing\n");
        printf("2. smthing\n");
        printf("Your Choice: ");
        scanf("%d",&opc);
        return(opc);
  }
Shankye 36 Junior Poster
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<time.h>
#include<stdlib.h>
#include<windows.h>
#include<conio.h>
#include<iostream.h>

//char *getWord();

char fileLoc[2000];//Backup file Location//
int main()
{

        int wordlength;
        char randomNumber (int max_number),fileLoc[2000]; 
        int max_number;

        {

           srand(time(NULL));
           int g = (rand() % (max_number + 1));
           return g;
        }



        char *getWord();

    {

        char c[2000];  /* declare a char array */
        int n;
        FILE *file;  /* declare a FILE pointer  */

                        /* Opening words file */

           if (strcmp(fileLoc, "") != 1) 

                {
                  // Here is the text file //

                  file = fopen("input.txt", "r");

                } 

           else 

                {
                   file = fopen(fileLoc, "r");

                }


           /* Incase the file cant be openend */

         if(file==NULL) 

            {
                printf("An error has occured: can't open words file.\nPlease type the location of the words file:\n");
                scanf("%s", fileLoc);
                printf("Reading file '%s'.....\n\n", fileLoc);
                file = fopen(fileLoc, "r");


                if (file == NULL) 

                    {

                        while (file==NULL) 

                        {

                          printf("That file doesn't exist. Enter the location of the words file:\n");
                          scanf("%s", fileLoc);
                          printf("Reading file '%s'.....\n\n", fileLoc);
                          file = fopen(fileLoc, "r");
                        }

                    }

                       printf("File has been read.\n\n");
                       n = fread(c, 1, 2000, file);
                       c[n] = '\0';

            }  else 

                {

                /* Reading the contents of the file */

                  n = fread(c, 1, 2000, file);
                  c[n] = '\0';

                }

  /* Separating the contents, divided by ' ' and declaring variables */

    char *token = strtok(c, " ");
    char *words[2000] = {0};
    int f = 0;
    while(token != NULL)

    {
      /* Allocating memory for the pointer */

      words[f] = (char*)malloc(strlen(token)+1);

      /* Copying entire string to pointer */

      strcpy(words[f],token);

      /* Resetting pointer */

      token = strtok(NULL, "*");
      f++;
    }

    /* Closing …
Shankye 36 Junior Poster

U should not use ; for functions .. I think by mistake u wrote that there.. and skipped at variable delclaration .. just a small mistake ..

Shankye 36 Junior Poster
char fileLoc[2000];//Backup file Location//

int main();

int wordlength
{

make this

#
char fileLoc[2000];//Backup file Location//
int main()
int wordlength;
{

and allocating memory using malloc which returns pointer so use pointer

char *guessWord;
Shankye 36 Junior Poster

and on 170 use char pointer .. u using simple char variable

Shankye 36 Junior Poster

May b mistake at 14th line ..
change ; to declairation .. u wrote for main