Copying multiple files into one??
may be cat command you are saying abt?
Copying multiple files into one??
may be cat command you are saying abt?
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 ..
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);
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
Post your code .. We will help to solve probs ..
wooww Cool ..
and portable too ;-)
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
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..
Lol Rofl
Oh i dint knew that ..
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 ;-))
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
*
**
***
****
....
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);
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
Location Value
and another is RValue which is Read value..
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
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..
If problem solved please mark it solved
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
Post what all you have ..
How you going to calc grade using percentage thn anyone 'll help you
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 ..
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 ..
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..
It counts upper lower and digits in a file ..
Hey tht snake game is really cool ..
u may be interested in these too
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
Is it a C program ??????????????????????
Post in Java discussion thread ..
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();
}
OMG!!
what actually you are trying to do???
Is this you talking about??
while( (ch=getchar())!="\n" && i < MAX_SIZE)
{
input[i] = ch;
i++;
}
input[i] = "\0";
Ya.. now your program must works fine ..
Oopss sorry new to this place ..
There are many ways by which u can copy files ..
copying FILE *fs to *ft ...
while( (ch = getc(fs)) != EOF)
{
putc(ch,ft);
}
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;
}
how flushing stdin causes contents of output stream to be flushed????
It worked fine many times for me ..
U can use fflush(stdin) also ..
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;
Check with Dev-C++ .. Worked fine for me ..
U can add current directory to $PATH
PATH=$PATH:.
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 ..
I dont have clear idea but write() function, may be it writes in binary mode so may be thats why text editors complaining ..
Ya dude ..
Break your program into functions..
and post part which is erroneous ..
Thanks for link Walt ..
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);
}
#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 …
U should not use ; for functions .. I think by mistake u wrote that there.. and skipped at variable delclaration .. just a small mistake ..
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;
and on 170 use char pointer .. u using simple char variable
May b mistake at 14th line ..
change ; to declairation .. u wrote for main