我试图将 scanf 中的名称放入一个数组中,但不知道它将在程序中的位置。我需要名称数组来根据名称大小和大小写字符为每张卡创建账单。
这是程序的文件输出部分的功能。
int createoutfilecard(int y)
{
int spaceCounter; // The number of spaces we want to start with based on what level tree we are making
int originalSpaceCounter; // We need to keep this for the end with the stem of the tree
int spaceLoopCounter; // This is for our space control structure
int spaceLoopCounter2; // This is just to have a different one for the end space control structure
int treeLoopLevel = 0; // This is the level of tree we want to make
int starNumber = 1; // This is the number of stars we need and we always start with 1
int starLoopCounter; // This is the counter for the star loop structure
int x; // Just a generic counter for the overall loop
char word[50];
int c;
int b;
int q;
int p;
char str[80];
if (y== 1){
printf("Enter the tree size: ");
scanf("%d", &treeLoopLevel);
//for i < total number of cards
//loop through entire program
//printf("invalid input");
printf("Enter the number of cards: ");
scanf("%d", &q);}
for (p=1; p<=q; p++){
if (treeLoopLevel>=1 && treeLoopLevel<=10){
printf("Enter the recipient's name: ");
}
else{
printf("invalid input");
printf("Enter the tree size: ");
scanf("%d", &x);}
if (scanf(" %49s", &word)==1){
system("cls");
strcpy(str,"christmascard");
strcat(str,word);
strcat(str,".txt");
printf("The file will be located at %s\n", str);
outFile=fopen(str, "w");
for (c=0; c<=79; c++){
fprintf(outFile, "-");
}
fprintf(outFile, "\n");
while (b=0)
fprintf(outFile, "\n \n");
fprintf(outFile, "- Happy Holidays %s -" , word);
spaceCounter = 39; //(treeLoopLevel * 2) + 1; This is going to be our space counter limit for our loop further down
originalSpaceCounter = spaceCounter - 1; // We will need the original number minus one for the trunk of the tree at the end
fprintf(outFile, "\n");
for(x = 1; x <= treeLoopLevel; x++) // Overall Loop
{
for(spaceLoopCounter = 1; spaceLoopCounter <= spaceCounter; spaceLoopCounter++) // This does our beginning spaces
{
if(spaceLoopCounter == 1) // We need to start with the minus only
{
fprintf(outFile, "-");
}
else // We need the rest to be spaces so any other condition then the first one is going to be a space
{
fprintf(outFile, " ");
};
};
for(starLoopCounter = 1; starLoopCounter <= starNumber; starLoopCounter++) // This is the star loop that only goes up to what starNumber is set to
{
fprintf(outFile, "*");
};
starNumber = starNumber + 2; // This is for incrementing the number of stars for our counter limiter for the star loop above
for(spaceLoopCounter2 = 1; spaceLoopCounter2 <= spaceCounter; spaceLoopCounter2++) // This is going to be for the right side so we have the right number of spaces
{
fprintf(outFile, " ");
};
fprintf(outFile, "-\n");
spaceCounter = spaceCounter - 1; // This modifies the space counter after it has been used on both sides for the next iteration of the overall loop
};
fprintf(outFile, "-"); // Tree trunk line minus sign on the left
for(spaceLoopCounter = 1; spaceLoopCounter <= originalSpaceCounter; spaceLoopCounter++) // Spaces for the tree trunk on the left
{
fprintf(outFile, " ");
};
fprintf(outFile, "||"); // Tree Trunk
for(spaceLoopCounter = 1; spaceLoopCounter <= originalSpaceCounter; spaceLoopCounter++) // Spaces for the tree trunk on the right
{
fprintf(outFile, " ");
};
fprintf(outFile, "-\n"); // Tree trunk line minus sign on the right
fprintf(outFile, "-"); // Tree trunk pot minus sign on the left
for(spaceLoopCounter = 1; spaceLoopCounter <= originalSpaceCounter; spaceLoopCounter++) // Spaces for the tree trunk pot on the left
{
fprintf(outFile, " ");
};
fprintf(outFile, "()");
for(spaceLoopCounter = 1; spaceLoopCounter <= originalSpaceCounter; spaceLoopCounter++) // Spaces for the tree trunk pot on the right
{
fprintf(outFile, " ");
};
fprintf(outFile, "-\n"); // Tree trunk line minus sign on the right
};
for(c=0;c<58;c++)
{
fprintf(outFile, "\n");
fprintf(outFile, "-"); //print left side
for(b=0;b<78;b++)
{
fprintf(outFile, " "); //print spaces
}
fprintf(outFile, "-"); //print right side
}
fprintf(outFile, "\n");
for (c =1; c <=80;c++)
fprintf(outFile, "-");
fclose(outFile);
}
return 0;
}