Hello, I've created a fully functioning code based on your assistance. But I now must adapt it a bit to serve its purpose. Wondering if you still had any tips to assist me.
Code:
#include <stdio.h>
#include <math.h>
#include <quadmath.h>
typedef __float128 real;
typedef __float128 doublereal;
#include <stdlib.h>
#include <string.h>
//Declare global variables
char line[1500], c, r[1500];
int i, j, num;
FILE *fptr1, *fptr5;
int main()
{
// Close and reopen fptr1 to reinitialize the file
fclose(fptr1);
fptr1 = fopen("Surrogate_Design_Space_1_Option.in","r");
fptr5 = fopen("TESTFILE.out", "w");
// Counts the number of columns the shape function coefficients use in fptr1
fscanf(fptr1, "%s", line); //Scans/Stores the First Character "RunCounter" in line
fgets(line, 1500, fptr1); //Scans/Stores the rest of the first row in line (Over rides last fscanf)
num = countcolumns(line); // Calls function "countcolumns" on character "line" to count the amount of columns in the string
// printf("The string %s has %d columns\n", line, num); // prints the string thats evaluated above as a check
printf("Number of columns in fptr1 = %d\n", num); // Prints the Number of columns as a check
//Close Surrogate Run_Finite_Difference_81.in file
fclose(fptr1);
return 0;
}
int countcolumns (const char *s)
{
int columns = 0;
printf("Baseline\n");
while (isspace(*s)) // Skip leading whitespace
s++;
printf("%c", *s);
fprintf(fptr5, "%c", *s);
while (*s != '\0') { // While not at end of string
columns++;
while (*s != '\0' && !isspace(*s)) { // While NOT spaces
s++; // Go to next character in string
printf("%c", *s);
fprintf(fptr5, "%c", *s);
}
while (isspace(*s)) {// Skip inter-column whitespace
s++;
printf("\n%c", *s);
fprintf(fptr5, "\n%c", *s);
}
}
return columns;
}
The output is below for this example:
Al[5,0]
Au[2,0]
Au[3,0]
Au[4,0]
Au[5,0]
Au[6,0]
Au[8,0]
Au[7,0]
LDout
Where i would like:
Al[5,0] (m)
Al[5,0] (p)
Au[2,0] (m)
Au[2,0] (p)
Au[3,0] (m)
Au[3,0] (p)
Au[4,0] (m)
Au[4,0] (p)
Au[5,0] (m)
Au[5,0] (p)
Au[6,0] (m)
Au[6,0] (p)
Au[8,0] (m)
Au[8,0] (p)
Au[7,0] (m)
Au[7,0] (p)
So basically i want to be able to write each string of the character "line" twice. duplicating each one and writing the (m) and (p) as shown.
I haven't attempted (m) and (p) yet because I've been stuck on duplicating for so long. Im not to worried about implementing this. seems straight forward but duplicating is giving me big problems
I've tried combination of techniques using scanf, fgets, ect. to try and scan the last line created then printing it again. but the output stops at Al[5,0]. Sample below of where i was inserting it. right after the 3rd while loop.
Code:
int countcolumns (const char *s)
{
int columns = 0;
printf("Baseline\n");
while (isspace(*s)) // Skip leading whitespace
s++;
printf("%c", *s);
fprintf(fptr5, "%c", *s);
while (*s != '\0') { // While not at end of string
columns++;
while (*s != '\0' && !isspace(*s)) { // While NOT spaces
s++; // Go to next character in string
printf("%c", *s);
fprintf(fptr5, "%c", *s);
}
scanf("%s", r);
printf("hey%s", r);
// fgets(r, 100, fptr5);
// printf(" hey %s", r);
// printf("%s", *s);
while (isspace(*s)) {// Skip inter-column whitespace
s++;
printf("\n%c", *s);
fprintf(fptr5, "\n%c", *s);
}
}
return columns;
}
Any help would be greatly appreciated!