I just finally got the cs50 library working after a lot of trial on my Windows Vscode. Now, the problem is that the get_string
function would not work as used below:
int main(void)
{
string s = get_string("Enter string: ");
// ensure string was read
if (s == NULL)
{
return 1;
}
string next = get_string("You just entered %s. Enter a new string: ", s);
if (next == NULL)
{
return 1;
}
printf("Your last string was %s\n", s);
}
When I write
string name = get_string("Give me a name:");
I get the error
In file included from hello.c:1:0:
cs50.c:78:8: note: expected ‘char **’ but argument is of type ‘char *’
string get_string(va_list *args, const string format, ...)
^~~~~~~~~~
hello.c:10:16: error: too few arguments to function ‘get_string’
string name = get_string("Give me a name:");
^~~~~~~~~~
In file included from hello.c:1:0:
cs50.c:78:8: note: declared here
string get_string(va_list *args, const string format, ...)
Here is my code. I am basically testing the get_string
function not necessary needed in the function.
#include "cs50.c"
#include "cs50.h"
#include <stdio.h>
#include <stdlib.h>
int main()
{
char str[20] = "#";
string name = get_string("Give me a name:");
printf("What height of pyramid \n");
int user;
if(scanf("%d", &user))
{
for (int i =0; i< 8; i++)
{
if(user <= 0 || user > 8 )
{
printf("Height: %d \n", user);
printf("Provide value between 1 and 8 \n");
scanf("%d", &user);
}
}
printf("\n");
int i;
for (i = 1; i <= user; i++) {
for(int k = user; k > i; k--){
putchar(' ');
}
int j;
for (j = 0; j < i; j++) {
putchar('#');
}
putchar('\n');
}
return EXIT_FAILURE;
}
}
I expect to write
string s = get_string("Enter string: ");
and get a prompt in the terminal when running the code.