#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define FILE_IN "lab4.dat"
//define FILE_IN "lab4sample.dat"
#define FILE_OUT "lab4.out"
int main(void)
{
double radius, height, area, volume;
int count;
FILE * In;
FILE * Out;
In = fopen(FILE_IN, "r");
if (In == NULL) {
printf("Error on opening the input file \n");
}
Out = fopen(FILE_OUT, "w");
if (Out == NULL) {
printf("Error on opening the output file \n");
}
fprintf(Out, "Name. Lab4. \n");
while((fscanf(In, "%lf%lf", &radius, &height)) == 2) {
area = M_PI * radius * radius;
volume = M_PI * radius * radius * height;
count++;
fprintf(Out, "\nCylinder %1d", count);
fprintf(Out, "\nThe radius is: %9.3f", radius);
fprintf(Out, "\nThe height is: %9.3f", height);
fprintf(Out, "\nThe top area is: %9.3f", area);
fprintf(Out, "\nThe volume is: %9.3f\n", volume);
}
fclose(In);
fclose(Out);
return EXIT_SUCCESS;
}
for C
Here is code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define FILE_IN "lab4.dat"
//define FILE_IN "lab4sample.dat"
#define FILE_OUT "lab4.out"
int main(void)
{
double radius, height, area, volume;
int count = 0;
FILE *In;
FILE *Out;
In = fopen(FILE_IN, "r");
if (In == NULL)
{
printf("Error on opening the input file \n");
}
Out = fopen(FILE_OUT, "w");
if (Out == NULL)
{
printf("Error on opening the output file \n");
}
fprintf(Out, "Name. Lab4. \n");
while ((fscanf(In, "%lf%lf", &radius, &height)) == 2)
{
area = M_PI * radius * radius;
volume = M_PI * radius * radius * height;
count++;
fprintf(Out, "\nCylinder %d", count);
fprintf(Out, "\nThe radius is: %9.3f", radius);
fprintf(Out, "\nThe height is: %9.3f", height);
fprintf(Out, "\nThe top area is: %9.3f", area);
fprintf(Out, "\nThe volume is: %9.3f\n", volume);
}
fclose(In);
fclose(Out);
return EXIT_SUCCESS;
}
Output:
#include <stdio.h> #include <stdlib.h> #include <math.h> #define FILE_IN "lab4.dat" //define FILE_IN "lab4sample.dat" #define FILE_OUT "lab4.out" int...
Convert this code from C to C++ include <stdio.h> include <locale.h> void filtre (double x. double yll, double yol, int , int N) int Nn-10000 int main) setlocale (LC ALL,") double x(Nm) , y [ Nm],yo Nml®(0.0); int m; FILE dosyal-fopen("D:/veri/673.txtr FILE dosya2-fopen("D:/veri/data2.txt int i-0 while( feof (dosyal)) fscanf (dosyal, " ",xi sytil) fclose (dosyal) int Nij printf("Pencere Genişligi scanf() 3 filtre(x,y.Yo,m,N) for(int k-0keNkt+)fprintf (dosya2, 10.41 10.411 0.41fn",x[k],y[k].yo[k]) fclose(dosya2) void filtre (double x double y. double yoll, int m, int...
Heres what I have so far: /* Preprocessor directives */ #include <stdio.h> #include <math.h> #define pi 3.14159 #define inputfile "c:\\engr 200\\oil_explore.txt" #define outputfile "c:\\engr 200\\oil_report.txt" /* Main function */ int main(void) { /* Declare variables */ double ratio, depth, ideal_charge, length, weight, number_sticks, wellsite; int i; FILE *explore, *report; /* Open input file */ explore = fopen(inputfile,"r"); report = fopen(outputfile,"w"); /* Verify input file */ if(explore == NULL) { printf("\n\nERROR OPENING INPUT FILE\n\nPROGRAM TERMINATED\n\n"); return 0; } /* Read...
#include <stdio.h> #include <stdlib.h> #include <strings.h> #include <unistd.h> #include <pthread.h> pthread_mutex_t mtx; // used by each of the three threads to prevent other threads from accessing global_sum during their additions int global_sum = 0; typedef struct{ char* word; char* filename; }MyStruct; void *count(void*str) { MyStruct *struc; struc = (MyStruct*)str; const char *myfile = struc->filename; FILE *f; int count=0, j; char buf[50], read[100]; // myfile[strlen(myfile)-1]='\0'; if(!(f=fopen(myfile,"rt"))){ printf("Wrong file name"); } else printf("File opened successfully\n"); for(j=0; fgets(read, 10, f)!=NULL; j++){ if (strcmp(read[j],struc->word)==0)...
Create another program that will prompt a user for input file. The user will choose from 4 choices: 1. Display all positive balance accounts. 2. Display all negative balance accounts. 3. Display all zero balance accounts. 4. End program. C PROGRAMMING my code so far #include<stdlib.h> #include<stdio.h> int main(void) { int request; int account; FILE *rptr; char name[20]; double balance; FILE *wptr; int accountNumber; if((wptr = fopen("clients.dat","w")) == NULL) { puts("File could not be opened"); } else {...
#include <stdio.h> #include <stdlib.h> #include <string.h> #include<ctype.h> #define MAX_LEN 255 int numWords(char *str); int numDigit(char *str); int numUppltr(char *str); int numLwrltr(char *str); int punChar(char *str); char*readString(char *str); int main() { char givString[MAX_LEN]; puts("Enter your string(Max 255 characters):"); //readString(givString); gets(givString); printf("\nnumber of words :%d",numWords(givString)); printf("\nnumber of uppercase letters %d",numUppltr(givString)); printf("\nnumber of lowercase letters %d",numLwrltr(givString)); printf("\nnumber of punctuations %d\n",punChar(givString)); printf("\nnumber of digits:%d\n",numDigit(givString)); system("pause"); return 0; } char *readString(char *str) { int ch, i=0; while((ch=getchar())!=EOF && ch!='\n') { if(i) { str[i]=ch; i++; }...
convert this code from C to C++ include <stdio.h> include <locale.h> void filtre (double x. double yll, double yol, int , int N) int Nn-10000 int main) setlocale (LC ALL,") double x(Nm) , y [ Nm],yo Nml®(0.0); int m; FILE dosyal-fopen("D:/veri/673.txtr FILE dosya2-fopen("D:/veri/data2.txt int i-0 while( feof (dosyal)) fscanf (dosyal, " ",xi sytil) fclose (dosyal) int Nij printf("Pencere Genişligi scanf() 3 filtre(x,y.Yo,m,N) for(int k-0keNkt+)fprintf (dosya2, 10.41 10.411 0.41fn",x[k],y[k].yo[k]) fclose(dosya2) void filtre (double x double y. double yoll, int m, int...
#include <stdlib.h> #include <stdio.h> #include "main.h" #define MAX_NUM_LENGTH 11 void usage(int argc, char** argv) { if(argc < 4) { fprintf(stderr, "usage: %s <input file 1> <input file 2> <output file>\n", argv[0]); exit(EXIT_FAILURE); } } /* This function takes in the two input file names (stored in argv) and determines the number of integers in each file. If the two files both have N integers, return N, otherwise return -1. If one or both of the files do not exist, it...
Fix the errors in C code #include <stdio.h> #include <stdlib.h> void insertAt(int *, int); void Delete(int *); void replaceAt(int *, int, int); int isEmpty(int *, int); int isFull(int *, int); void removeAt(int *, int); void printList(int *, int); int main() { int *a; int arraySize=0,l=0,loc=0; int choice; while(1) { printf("\n Main Menu"); printf("\n 1.Create list\n 2.Insert element at particular position\n 3.Delete list.\n4. Remove an element at given position \n 5.Replace an element at given position\n 6. Check the size of...
In which line of the following code the first error is appeared (if any)? #include 2 int main() <stdio.h> 4 file p: 6 fopen("newname . txt", "rb"); *p if = (P NULL) 8 perror( "Error opening file") 9 else f while (fgetc(p)- eof) 12 13 if (feof(p)) 14 15 else 16 17 Fclose(p) 18 19 20 return e; 21 printf("%d\n", n); puts("End-of-File was not reached.) 23 O 10 0 17
devmem2.c #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <errno.h> #include <signal.h> #include <fcntl.h> #include <ctype.h> #include <termios.h> #include <sys/types.h> #include <sys/mman.h> #define FATAL do { fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", \ __LINE__, __FILE__, errno, strerror(errno)); exit(1); } while(0) #define MAP_SIZE 4096UL #define MAP_MASK (MAP_SIZE - 1) int main(int argc, char **argv) { int fd; void *map_base = NULL, *virt_addr = NULL; unsigned long read_result, writeval; off_t target; int access_type = 'w'; if(argc...