我如何将字符串数组元素中的多个字符放入 TEXT 中,因为它必须是指向字符 [outtextxy(X, Y, TEXT)] 的指针?
How can I put more than one character from an element of string array inside TEXT as it must ba a pointer to a character [ outtextxy(X , Y, TEXT) ]?
我想将 arr[] 中的值放入 outtextxy() 函数。我不能将 arr[] 声明为 char,因为其中有 10、11 ... 之类的值,而 outtextxy() 函数不允许我将字符串放在那里。我还尝试制作一个指针来保存 arr[] 的值,但它不起作用。
#include <stdio.h>
#include <graphics.h>
#include <cmath>
int main()
{
int a = 450, b = 450;
int midX = a/2, midY = b/2;
initwindow(a, b);
char t[50];
std::string arr[] = {"3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "1", "2"};
std::string* ptr = &arr[2];
for (int x=0; x<12; x++){
int angle = 60*x;
double rad = (3.14*angle)/360.0;
int r = 155;
outtextxy(midX+r*cos(rad) , midY-155+r*sin(rad)+100, ptr);
getch();
}
getch();
closegraph();
return 0;
}
经过大量搜索,我找到了答案。我必须让 arr[] 不是字符串而是二维字符数组。它解决了所有问题。
#include <stdio.h>
#include <cmath>
#include <graphics.h>
int main()
{
int a = 450, b = 450;
int midX = a/2, midY = b/2;
initwindow(a, b);
char t[50];
char arr[][3] = {"3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "1", "2"};
char* ptr = &*arr[2];
for (int x=0; x<12; x++){
int angle = 60*x;
double rad = (3.14*angle)/360.0;
int r = 155;
outtextxy(midX+r*cos(rad) , midY-155+r*sin(rad)+100, ptr);
getch();
}
getch();
closegraph();
return 0;
}
我想将 arr[] 中的值放入 outtextxy() 函数。我不能将 arr[] 声明为 char,因为其中有 10、11 ... 之类的值,而 outtextxy() 函数不允许我将字符串放在那里。我还尝试制作一个指针来保存 arr[] 的值,但它不起作用。
#include <stdio.h>
#include <graphics.h>
#include <cmath>
int main()
{
int a = 450, b = 450;
int midX = a/2, midY = b/2;
initwindow(a, b);
char t[50];
std::string arr[] = {"3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "1", "2"};
std::string* ptr = &arr[2];
for (int x=0; x<12; x++){
int angle = 60*x;
double rad = (3.14*angle)/360.0;
int r = 155;
outtextxy(midX+r*cos(rad) , midY-155+r*sin(rad)+100, ptr);
getch();
}
getch();
closegraph();
return 0;
}
经过大量搜索,我找到了答案。我必须让 arr[] 不是字符串而是二维字符数组。它解决了所有问题。
#include <stdio.h>
#include <cmath>
#include <graphics.h>
int main()
{
int a = 450, b = 450;
int midX = a/2, midY = b/2;
initwindow(a, b);
char t[50];
char arr[][3] = {"3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "1", "2"};
char* ptr = &*arr[2];
for (int x=0; x<12; x++){
int angle = 60*x;
double rad = (3.14*angle)/360.0;
int r = 155;
outtextxy(midX+r*cos(rad) , midY-155+r*sin(rad)+100, ptr);
getch();
}
getch();
closegraph();
return 0;
}