标签: variables

在C中,如何在同一个变量中存储String类型和int类型?

我想在一个名为X的变量中存储一个整数和一个String,然后显示它.

int X;
printf("enter a number or a name")
scanf("%d", &X);
printf("%d", X);
Run Code Online (Sandbox Code Playgroud)

显然我需要用String类型和int类型声明变量X,我该怎么做呢?谢谢

c variables storage types

-4
推荐指数
2
解决办法
5653
查看次数

在C中的字符串中输出变量内容

在C++中,我执行以下操作:

cout<<"a["<<i+1<<",<<"j+1<<"]= "; cin>>a[i][j]; 
Run Code Online (Sandbox Code Playgroud)

(显示:"a [1] [1] ="并获取[0] [0]的输入;基本上i + 1只是查看器的一个技巧,因为我想使用0中的数组而不是1那不是重点).

如何使用printf和scanf在C中完成此操作?显然C不喜欢

printf("a["<<i+1<<","<<j+1<<"]= "); scanf("%d", a[i][j]);
Run Code Online (Sandbox Code Playgroud)

基本上,什么相当于

<<i+1<< 
Run Code Online (Sandbox Code Playgroud)

在C语言?

c string variables output

-4
推荐指数
1
解决办法
106
查看次数

代码或我的IDE/comp中的问题被窃听?

我尝试刷新我今天用C语言提供的一些有限的知识,并且我在非常简单的代码上遇到了一些问题,我无法定义它们的本质....

或者我做了一个非常愚蠢的错误或者有些事情被窃听......

我使用了codeblocks v12.11 IDE并将其设置为C中的程序项目(这是下载二进制文件的链接:http://www.codeblocks.org/downloads/binaries)我使用了它的~90MB版本附带GCC编译器....

我在windows xp和windows 7机器上使用了这个IDE(和dev-C++ http://www.bloodshed.net/download.html-使用不同的编译器)...

两个代码(单独构建和编译不起作用)

第一个代码是一个非常简单的代码,它只是将两个值相加并将它们赋予一个"a"变量......

这里是:

#include <stdio.h>

int main()
{
    int a,b,c,f;
    b=10;
    scanf("%d",&c);
    a=b+c;
    printf("%40s, %d",a);

return(0);
}
Run Code Online (Sandbox Code Playgroud)

因为它在上面它不能全部工作!(我的目的是在lineoutput的右边显示var"a"40个空格的值)它返回一个空消息或者窗口弹出一个致命的错误窗口...(取决于我的电脑昨天的情绪只有今天控制台返回了一条空消息,它决定告诉windows控制台窗口没有响应...)

如果我编辑这样的代码:

int main()
{
int a,b,c,f;
b=10;
scanf("%d",&c);
a=b+c;
printf("%40s"); 
printf("%d",a);

return(0);
}
Run Code Online (Sandbox Code Playgroud)

它有效,但在显示ascII字符的任何intreusult前面..像这样:

(奇怪的是,当我输入数字7时,它不显示一个字符,而是我的电脑发出哔哔声......如果我输入一个非数字字符,它会像这样无休止地循环:

如果我将变量的类型更改为FLOAT一切正常..但是你猜对了结果不是整数....

有趣的是,如果所有内容都转向FLOAT,但是在scanf属性上,输入设置为int [scanf("%d",&c);]程序仍然可以工作并将结果显示为浮点数但是再次使用ascii字符他们......

另一个奇怪的事情是,当我输入像99999这样的大数字时,它会显示多个ascii字符,我希望它只返回没有ascii字符的结果,因为ascii字符代码是1到255之类的东西......

所以

  • 问题A:是我的编译器还是IDE错误(是全新安装)?

  • 问题B:如果我该怎么办?重新安装吗?一样的东西

    发生...

  • 问题C:如果它不是软件问题(IDE/COMP等)那么为什么会出现那些ascii字符?

PS要将所有结果一起投影并采用上面的打印屏幕框架,我使用了"while"循环它不会改变任何相同的结果,当我构建和编译代码而没有while循环时...但是要确保我粘贴使用"while"命令修改代码,以便在一个控制台中显示所有结果,以便我可以对它们进行打印.

int main()
{
int a,b,c,f;
b=10;
while(b=10){
scanf("%d",&c);
a=b+c;
printf("%40s"); 
printf("%d",a);
}        
return(0);
}
Run Code Online (Sandbox Code Playgroud)

c compiler-construction variables debugging

-4
推荐指数
1
解决办法
138
查看次数

未定义的变量

我已经定义了2个变量,包括联系人和衬衫.正如你所看到的那样,他们也在标题中.我仍然得到两个变量都未定义的消息.

我收到此错误消息:

(!)SCREAM:忽略(!)的错误抑制

注意:未定义的变量:第17行的C:\ wamp\www\Test\shirts4mike\inc\header.php中的部分

调用堆栈#TimeMemoryFunctionLocation 10.0003243592 {main}()..\index.php:0

20.0006246920 include('C:\ wamp\www\Test\shirts4mike\inc\header.php')..\index.php:3">

第18行也是如此.

shirts.php:

     <?php
            $pageTitle = "Mike's Full Catalog of Shirts";
            $section = "shirts";
            include('inc/header.php'); ?>

                    <div class="section page">
                            <h1>Mikes&rsquo;s Full Catalog of Shirts</h1>
                    </div>

            <?php include ('inc/footer.php'); ?>
Run Code Online (Sandbox Code Playgroud)

contact.php:

<?php
    $pageTitle = "Contact Mike";
     $section = "contact";
     include('inc/header.php'); ?>

           <div class="section page">

           <h1>Contact</h1>

           </div>


<?php include ('inc/footer.php'); ?>
Run Code Online (Sandbox Code Playgroud)

header.php:

<html>
        <head>
                <title> <?php echo $pageTitle ?></title>
                <link rel="stylesheet" href="css/style.css" type="text/css">
                <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Oswald:400,700" type="text/css">
                <link rel="shortcut …
Run Code Online (Sandbox Code Playgroud)

php variables xdebug

-4
推荐指数
1
解决办法
2486
查看次数

无法解析变量?

我正在尝试编写一个创建随机拼写效果的程序,但"长度"无法解析为变量......

package Chaos;

import java.util.Random;

public class Effects {
    public static void main(String[] args) {

        String[] objects = { "Effect1", "Effect2", "Effect3", "Effect4" };

        int effect = objects.length;

        for (int i = 0; 1 < length; i++) {
            int rand = (int) (Math.random() * length);
            System.out.print(objects[rand]);
            System.out.print(" ");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

java variables

-4
推荐指数
1
解决办法
1315
查看次数

如何使用数组创建变量?

这是代码

        $get_favory = mysql_query("SELECT * FROM favory WHERE user1='$username'");

        $values = "";

        while($fav = mysql_fetch_assoc($get_favory)) {
        $user2 = $fav['user2'];
        $values = " OR added_by='".$user2."'";
        }

        echo $values;
Run Code Online (Sandbox Code Playgroud)

值变量必须是这样的:OR added_by='zac' OR linked_by='john' OR linked_by='emily'
但我得到这个结果:OR linked_by='zac'

我必须做什么?

php variables do-while

-4
推荐指数
1
解决办法
57
查看次数

有没有更简单的方法:if(num1> num2 && num1> num3),要比较更大的变量列表?

我想知道(只是为了知道)是否有办法用更简单的代码执行以下指令:(C++)

if(a > b && a > c && a > d)
Run Code Online (Sandbox Code Playgroud)

有可能用这样的东西替换它:

 if(a > b, c, d)
Run Code Online (Sandbox Code Playgroud)

c++ variables relational

-4
推荐指数
1
解决办法
167
查看次数

为什么会发生这种意外的变量?

        #include <iostream>
#include <fstream>
using namespace std;
const int maxsize=20;
class IntStack{
private:
    int element[maxsize],topindex;
public:
    IntStack(){topindex=-1;}
    int getTI(){
        return topindex;
    }
    int top(){
        if(topindex==-1)
            exit(-1);
        return element[topindex];
    }
    int top(int *t){
        if(topindex==-1)
            return -1;
        t=&element[topindex];
        return 0;
    }
    int pop(){
        if(topindex==-1)
            exit(-1);
        topindex--;
        return element[topindex+1];
    }
    int pop(int *t){
        if(topindex==-1)
            return -1;
        t=&element[topindex];
        topindex--;
        return 0;
    }
    int push(int e){
        if(topindex==19)
            return -1;
        topindex++;
        element[topindex]=e;
        return 0;
    }
    inline int empty(){return topindex==-1;}
    ostream& print(ostream& o){
        for(int i=0;i<=topindex;i++){
            o<<element[i]<<' '; …
Run Code Online (Sandbox Code Playgroud)

c++ variables methods

-5
推荐指数
1
解决办法
89
查看次数

如果$ _get为空,则设置变量默认值

下面是我用于我的一个页面的代码,但是如果$ _GET ['file']不存在,我想设置默认文件.

$catalogfile = $_GET['file'];
$catalogfileend = "Product_Catalog.xml";
$xmlfile = $catalogfile . $catalogfileend;
$startPage = $_GET['page'];
Run Code Online (Sandbox Code Playgroud)

php xml variables

-5
推荐指数
1
解决办法
2530
查看次数

字母'n'在Python中是无效的语法?

它在我的程序中早先作为变量名称工作现在突然Python在我的程序中将字母"n"作为无效语法返回.

知道为什么,以及如何解决这个问题?

bad_input=True
while bad_input:
    bad_input=False
    User_Choice=int(input('Which frame would you like to choose(1,2,3 represent positive selections, 4,5,6 represent -1,-2, and -3 respectively')
    n = 3
    if User_Choice== int(1):
        Chunks=[RNA_Comp[i:i+n] for i in range(0, len(RNA_Comp), n)]
    if User_Choice== int(2):
        Chunks=[RNA_Comp[i:i+n] for i in range(1, len(RNA_Comp), n)]
    if User_Choice== int(3):
        Chunks=[RNA_Comp[i:i+n] for i in range(2, len(RNA_Comp), n)]
    else:
        print('Please select an integer value from 1 to 6')
        bad_input=True
Run Code Online (Sandbox Code Playgroud)

python variables syntax

-5
推荐指数
1
解决办法
4517
查看次数