Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Nov 2003
    Location
    USA
    Posts
    217
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How do I set variables?

    Hello, I have been trying to set variables for a long time and I can't figer it out!
    So If you know how to set variables in C, PLEASE POST IT HERE!

  • #2
    Regular Coder
    Join Date
    Feb 2003
    Location
    California
    Posts
    925
    Thanks
    0
    Thanked 0 Times in 0 Posts
    int c;


    for vars to be set in C they need to be declared at the begining of the method or main functions...


    Jason

  • #3
    Regular Coder
    Join Date
    Nov 2003
    Location
    USA
    Posts
    217
    Thanks
    0
    Thanked 0 Times in 0 Posts
    umm.... ok.
    do you know how to do this in C:
    Code:
    <script>
    <!--
    var TEST = prompt ("Type some thing","")
    TEST2=10
    if (TEST2 == "10" || TEST == "20"){
    document.write("Hello")
    } else {
    document.write("hi")
    }
    //-->
    </script>
    Can you do this in C?
    My book leaves out brackets in there syntax so I get a lot of errors when I try stuff.

    This is how you display words right?
    Code:
    printf("words are in here")

  • #4
    Regular Coder
    Join Date
    Feb 2003
    Location
    California
    Posts
    925
    Thanks
    0
    Thanked 0 Times in 0 Posts
    var TEST = prompt ("Type some thing","")
    TEST2=10
    if (TEST2 == "10" || TEST == "20"){
    document.write("Hello")
    } else {
    document.write("hi")
    }


    PHP Code:
    #include <stdio.h>

    int main () {
    char TEST [20]= "type something";
    int TEST2 10;

    if ( 
    TEST2 == 10 || TEST2 == 20 ){
        
    printf("%s","Hello");
    }
    else {
        
    printf("%s","hi");
    }

    return 
    0;


    Jason

  • #5
    Regular Coder
    Join Date
    Nov 2003
    Location
    USA
    Posts
    217
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the code doesnt prompt me to set the variable TEST.
    Thank you for your help!

  • #6
    Regular Coder
    Join Date
    Dec 2003
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You have to use printf to print the prompt, and then scanf to get the value:
    Code:
    #include <stdio.h>
    
    int main () {
      char text[20];
      printf("Enter a string:\n");
      scanf("%s",text);
      printf("You entered : %s.\n",text);
      return 0;
    }
    shmoove

  • #7
    Regular Coder
    Join Date
    Feb 2003
    Location
    California
    Posts
    925
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    #include <stdio.h>



    int main () {

    char TEST [20];

    int TEST2 10;

       
    //shmooves coded added here....
      
    printf("Type Something\n");
      
    scanf("%s",TEST);
      
    printf("You entered : %s.\n"TEST);

    if ( 
    TEST2 == 10 || TEST == "20" ){

        
    printf("%s","Hello");

    }

    else {

        
    printf("%s","hi");

    }



    return 
    0;




    Next time try some code yourself, this was fairly simplistic...

    Jason

  • #8
    Regular Coder
    Join Date
    Nov 2003
    Location
    USA
    Posts
    217
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have three compilers, Bloodshed, HAM, and one from Barland.
    HAM has some sample code, I have been trying to chang it the way I want it for about a 5 months and nothing happins.

    Thank you for your help, I'm just going to get all the books on C at the library I can find.

  • #9
    Regular Coder
    Join Date
    Nov 2003
    Location
    USA
    Posts
    217
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The code Jason has posted gets some where!
    I will take it apart and see how He did it.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •