#simple error?

646 messages ยท Page 1 of 1 (latest)

restive nova
tardy zealotBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

#

@restive nova

Screenshots!

Your message appears to contain screenshots but no code. Please send code and error messages in text instead of screenshots if applicable!

restive nova
#

i made a thing to convert fareheit to cels

#

but in the example he got 2 numbers that are different

#

but veryy close

#

heres the code

#

    int number_of_entries;
    char numbers[200] = {};
    char *Numbers = numbers;
    int sum = 0;
    printf("How many Numbers would you like to convert? \n");
    scanf("%d", &number_of_entries);

    printf("Please enter the numbers you would like to convert: ");
    getchar();

    fgets(numbers, 200, stdin);

    int arrayNumbers[number_of_entries];

    for(int i = 0; i < number_of_entries; i++) {
            int fare = strtol(Numbers, &Numbers, 10);
            int cels;
            arrayNumbers[i] = fare;
            cels = ((arrayNumbers[i] - 32) * 5.0/9.0);

            printf("Cels: %d \n", cels);

    }

    return 0;
}
#

I am using the formula from F-> C

(x- 32 )* 5/9

inner jewel
#

you may want to round the formula's output so it does not get truncated before assigning it to cels

restive nova
#

@idle brook ill try it

inner jewel
#

im a different james but thumbs

restive nova
#

whoops

#

my b

#

how do you get roles in this discord

#

btw

inner jewel
#

i'm just being funny its fine

inner jewel
thorny quarry
restive nova
#

i meant like beginner

#

etc

thorny quarry
#

i know

inner jewel
#

react to the ๐Ÿ“– in #rules

restive nova
#

also

#

i rounded up

#

but still some are off

thorny quarry
restive nova
#

i just want beginner

#

lol

thorny quarry
#

then. do what james said

#

and read the rules

restive nova
#

okayy

#

you think you can help me with this issue

#

i think im using the right formula

#

i just dont know why those 2 numbers are different

#
            roundedCels = ceil(cels);```
#

and i did round it

#

up

#

too

thorny quarry
#

so (int) 75.6 is 75

restive nova
#

should i do long

thorny quarry
#

converting a number to long rounds it toward 0

restive nova
#

double?

#

double i decimal

#

rright

inner jewel
restive nova
#

is

#

int fare = strtol(Numbers, &Numbers, 10);

#

so im guessing i change this from int to double

thorny quarry
#

no, please stop guessin

restive nova
#

im not guessing

thorny quarry
#

like don't just throw out type names pls

#

yes you are

restive nova
#

ik double is decimal

#

so why wouldn't decimal be good

#

in this scenario

thorny quarry
#

strtol returns long

restive nova
#

oh

#

but you said long rounds towards 0

thorny quarry
#

ok please stop for 1 second

restive nova
#

ight

thorny quarry
#

converting a number to int, long etc rounds it toward 0, and assigning a value to an int rounds it

#

so cels = ((arrayNumbers[i] - 32) * 5.0/9.0); converts (arrayNumbers[i] - 32) * 5.0/9.0 to int and rounds toward 0

restive nova
#

gotcha

thorny quarry
#

so if arrayNumbers[i] is 168 then 75.555555555556 rounds to 75

#

and then

#

ceil(cels) is ceil(75)

#

which is already rounded

restive nova
#

so rounding a rounded number

#

pretty much

thorny quarry
#

you don't want to do ceil though

restive nova
#

i forgot which one rounded accurately but i know ceil rounds up

inner jewel
#

ceil always rounds up

restive nova
#

and floor rounds down

inner jewel
#

use round()

thorny quarry
#

most likely what you want is cels = round((arrayNumbers[i] - 32) * 5.0/9.0);

restive nova
#

oh

thorny quarry
#

you don't haveto change the type of anything

restive nova
#

so does the round take into fact first before rounding 0

#

ig cuz left to right

inner jewel
thorny quarry
restive nova
#

ah

#

it worked

#

thanks guys

inner jewel
#

๐Ÿ‘

restive nova
#

whoever that girl is

#

looked a lil sad

#

so i made her happy

#

๐Ÿ™‚

tardy zealotBOT
#

@restive nova Has your question been resolved? If so, run !solved :)

restive nova
#

!solved

tardy zealotBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

restive nova
#

hey I have another question.

#

im trying to use fgets to gather information

#

but the problem is if i go over 20 for the character limit

#

it just lags my command prompt

#
        scanf("%s", data);
        fgets(data, 200, stdin);
        getchar();
        printf("your data is: %s\n", data);```
#

im trying to do 200

#

so if i enter " ffghfgh fgh fgh fgh fgh fgh fgh " it prints it

thorny quarry
#

i think you meant to put getchar before fgets

restive nova
#

thanks

restive nova
#

i tried moving around the getChar but nothing

thorny quarry
restive nova
#

how do i get it back from scanf

thorny quarry
restive nova
#

im new

#

lmao

#

i know scanf only reads the first input

#

thats why im using fgets

#

i didnt know it takes it tho

#

good to know

#

anyways

#

should i not use scanf at all then

thorny quarry
#

yes, i think you can just remove scanf and getchar from that program

thorny quarry
#

anything that reads input also "takes" it

restive nova
#

ah

#

okay it worked yea

tardy zealotBOT
#

You can only open threads you own

restive nova
#

if i have an array

#

like

#

char data[] = { a b c d e }

#

can i print it like

#

%s, data[0]

#

to get a

thorny quarry
#

either putchar( data[0] )

#

or printf("%c", data[0])

restive nova
#

okay

#

%c worked

#

but in my notes i have

#

%c" when scanning for operators (+-/*).

#

i guess i meant single characters

#

not operators

inner jewel
#

%c is for char

restive nova
#

got it

thorny quarry
#

literal magnetic tapes

#

this fucking thing

#

that's why it reads things sequentially and has a "rewind" function

restive nova
#

what does stdio do

thorny quarry
#

records and plays back characters on tape access files

restive nova
#

ah

#

this may sound really dumb but why is this for loop only printing the first value if i did i++

        getchar();
        fgets(data, sizeof(data), stdin);

        printf("The %dth slot has a value of %c\n", i, data[i]);

    }```
#

if data equals "f f f f"

#

shouldn't it print

#

the 0th slot is f

#

the 1th slot is f

#

etc

#

(4 is the number of entries)

thorny quarry
#

and tell you the n'th entry of each separate line

#

i don't think fgets belongs in that loop

#

and i don't think getchar belongs anywhere

#

is that the same getchar i told you to get rid of?

restive nova
#

you told me to put it on top

thorny quarry
#

yeah, because of the scanf

#

and then you complained that scanf was taking input

restive nova
#

with 1 line

restive nova
#

oh i was mistaken then

thorny quarry
restive nova
#

no i do

#

like i have

#

char array { a b c d}

#

and then print the 0th slot is a

thorny quarry
#

if you don't want fgets to happen four times

restive nova
#

the 1th slot is b

thorny quarry
#

then don't put fgets in the loop that happens four times

restive nova
#

ill take it all out of the loop

#

except the print

#

now its doing this

#
{

    int number_of_entries;
    char data[200] = {};
    printf("How many entries will you have? ");
    scanf("%d", &number_of_entries);

    printf("Enter your data: ");
    getchar();
    fgets(data, sizeof(data), stdin);
        printf("your data is: %s\n", data);


    for (int i = 0; i < number_of_entries; i++) {

        printf("The %dth slot has a value of %c\n", i, data[i]);

    }
    return 0;
}
thorny quarry
#

because there's a between the f and the f

restive nova
#

how do i make it insert a comma

#

into the array

#

or is there a better way

thorny quarry
#

better way to do what? can you please be a little more specific about what you want

restive nova
#

so if my array is " a b c d"

#

i just want to be able to access things better

#

and if i can just do array[0,1,2,33,...]

thorny quarry
#

that's about as unspecific as you could possibly be

restive nova
#

yk what im saying

thorny quarry
#

no i do not know what you're saying

restive nova
#

hmm

thorny quarry
#

so if your array is "a b c d" then you just want to access things better

restive nova
#

how do i say this

#

lol

#

it sounds dumb

#

reading it

#

so my end goal is to take random groups of letters

#

and print out how many vowels there are

#

but im doing it inch by inch

#

input values: fghfghfgh fghfghfghfg fghfghfghf fghfgh

#

output: 0 0 0 0

#

since 0 vowels

#

but i want to try to figure that part out myself

#

i just dont know how to access each specific group of letters

thorny quarry
#

don't shoot me, but

#

you could read with scanf instead of fgets

#

note that i said "instead of" and not "before" or "after"

restive nova
#

i thought scanf only does the first grouping

thorny quarry
#

yeah, and then the next scanf does the next one

restive nova
#

oh in a for loop

#

ur sayiyng

#

but doesn't there need to be a comma in between them or no

thorny quarry
#

no, there doesn't need to be a comma

thorny quarry
restive nova
#
    {

        scanf("%s", data);

        printf("The %dth slot has a value of %c\n", i, data[i]);

    }```
#

like this?

thorny quarry
#

no

thorny quarry
restive nova
#

how would i make it do the whole word then the next word

thorny quarry
#

okay, can we stop and take a step back for a moment

restive nova
#

yyep

thorny quarry
#

so you want to read one whole line

restive nova
#

correct

thorny quarry
#

then split it into words

restive nova
#

spaces split them

#

yea

thorny quarry
#

and then print the number of vowels in each word

restive nova
#

wait sorry there could be more than one line too

#

abracadabra
pear tree
o a kak ushakov lil vo kashu kakao
my pyx

answer:
5 4 13 2

#

this is the example

#

but i dont want you to spoon feed me just kinda point me in the right direction

#

if posssible

thorny quarry
#

ok, so you don't actually want to split this into words

restive nova
#

its not like im doing homework or anything its just for my own benefit

thorny quarry
#

because you want o a kak ushakov lil vo kashu kakao to give you 13 and not 1 1 1 3 1 1 2 3

restive nova
#

correct

thorny quarry
#

so i am guessing that you just want to read however many lines it gives you, right?

restive nova
#

so first its going to ask how many lines are there

#

and then ill just put 4

#

for the example

#

then copy and paste that whole thing

#

abracadabra
pear tree
o a kak ushakov lil vo kashu kakao
my pyx

#

and then print out the vowels

#

still not really sure to do like if data.contains("a" , "e" "i" "o" "u" etc

#

ik in java

#

its .contains

#

for arrays

#

but idk in C

thorny quarry
#

that isn't what you want

#

the way to do "contains" would be strstr or strchr

#

but that would only tell you whether there is an a

#

and you want to know how many

restive nova
#

can't we make an array for integers and everytime we get a vowel

#

we add 1

#

to it

#

in the for loop

thorny quarry
#

sure. why an array, though?

restive nova
#

ig just an integer

#

ur right

#

a different integer

#

per line

#

so like int first

#

wait no that isn't a good idea

#

cuz

#

the real problem is 17 lines

#

so theres probably a better way to do it

#

im just trying to think out loud here because im not really sure

#

i was looking at this example

thorny quarry
restive nova
#
#include <string.h>


int main () {
   const char haystack[20] = "TutorialsPoint";
   const char needle[10] = "Point";
   char *ret;

   ret = strstr(haystack, needle);

   printf("The substring is: %s\n", ret);
   
   return(0);
}```
thorny quarry
#

you don't want to use strstr here

#

it can tell you whether there's an a in the line

#

but not how many

restive nova
#

ah

#
#include <string.h>
int main()
{
    char a[20]="Program";
    char b[20]={'P','r','o','g','r','a','m','\0'};

    // using the %zu format specifier to print size_t
    printf("Length of string a = %zu \n",strlen(a));
    printf("Length of string b = %zu \n",strlen(b));

    return 0;
}```
#
Length of string b = 7```
#

so strlen

#

can count all the letters

#

thats good

restive nova
#

or characters

thorny quarry
#

number of characters

restive nova
#

looking at this line if (data[x] == 'a') puts("found a");

#

ive never seen "puts" before

thorny quarry
#

puts(x) is the same as printf("%s\n", x)

#

just saves a little typing

restive nova
#

really?

#

bro

#

i never knew that

#

cuz in python

#

its just print(x)

#

anyways

thorny quarry
#

probably you don't want to print "found a" anyway

#

you want to count it

#

and you want to check for the other vowels too

restive nova
#

yea

#

one step at a time

#

its good

#

if (data[x] == 'a') puts("found a");

#

this is basically sayying

#

if the 0th slot == a put a

#

ig grouuping doesn't matter

#

because obviously doesn't contain a vowel

#

so we can just do line by line

thorny quarry
#

right

restive nova
#

is this not optimal

#

lol

thorny quarry
#

there is actually a trick you can do here

#

if (strchr("aeiou", data[x]))

#

which is like if "aeiou".contains data[x]

restive nova
#

what does strchr do

thorny quarry
#

note that it's strchr and not strstr

thorny quarry
restive nova
#

the order doesn't matter though right

#

it can just be anywhere

thorny quarry
#

right, because aeiou and oiaeu both contain a

restive nova
#

so for now

#

i was doing this

#
                        if (strchr("aeiouy", data[x])) {

                        printf("Got a vowel\n");

                    } else {

                        printf("No vowels.");
                    }
#

but before even giving the input

#

it just automatically says no vowels

#

i //'d it out

#

and the if statement works

#

so that is good

#

now we just need to tally them up

thorny quarry
restive nova
#

this is it right now

#

actually i just moved this printf("Total Numbers: %d ", total_letters);

#

out of the if statement

tardy zealotBOT
#
#include <stdio.h>
#include <stdlib.h>

int main() {
  int number_of_entries;

  char data[200] = {};
  printf("How many lines  will you have? ");
  scanf("%d", &number_of_entries);

  printf("Enter your data: ");

  for (int i = 0; i < number_of_entries; i++) {
    fgets(data, 200, stdin);
    int total_letters = strlen(data);
    for (int x = 0; x < total_letters; x++) {
      if (strchr("aeiouy", data[x])) {
        printf("Total Numbers: %d ", total_letters);
      }
    }
  }
  return 0;
}

joeyy
thorny quarry
#

so, the stuff in for (int i happens for each line

#

and the stuff in for (int x happens for each letter

restive nova
#

and x is each letter

#

right

#

yea

#

i got that

thorny quarry
#

(or really each character)

#

and you want to count the vowels in each line

#

so that count should be inside for (int i

#

but not inside for (int x

restive nova
#

before we do that i just have one question

thorny quarry
#

sure

restive nova
#

I put the printf("Total Numbers: %d ", total_letters);

#

here ill just send an updated thing

#

;format

stuck orchidBOT
#
Critical error:

Unable to find code to format!

Please reply to a message when executing this command or supply the code yourself in a code block or message attachment.

thorny quarry
#

so it should be inside for i

#

but not inside for x

restive nova
#

yyea

#

it is

thorny quarry
#

and if you want to print how many vowels you counted you should do it after counting them, not before

restive nova
#

ik i just wanted to make sure

#

the counter worked

#

so when you run the code

#

and it says

#

how many lines

#

and yoyu enter

#

it automatically sayys total number 1:

#

im just wondering how to get it to wait

#

until after you input "Enter your data:"

thorny quarry
#

you are getting bit by mixing scanf and fgets

restive nova
#

ik fgets does the whole string

#

but scanf only does whatever is before the space

thorny quarry
#

which is a space

#

so scanf doesn't take it

restive nova
#

ok

thorny quarry
#

if you type 2<enter>hello<enter> then
scanf reads "2"
first fgets reads "<enter>"
second fgets reads "hello<enter>"

tardy zealotBOT
#
#include <stdio.h>
#include <stdlib.h>

int main() {
  int number_of_entries;

  char data[200] = {};
  printf("How many lines  will you have? ");
  scanf("%d", &number_of_entries);

  printf("Enter your data: ");

  for (int i = 0; i < number_of_entries; i++) {
    fgets(data, 200, stdin);
    int total_letters = strlen(data);
    printf("Total Numbers: %d ", total_letters);

    for (int x = 0; x < total_letters; x++) {
      if (strchr("aeiouy", data[x])) {
        // add now
      }
    }
  }
  return 0;
}

joeyy
thorny quarry
#

you can put a scanf("\n") or getchar() after "enter your data"

restive nova
#

scanf is adding a space?

thorny quarry
#

no, it isn't

restive nova
#

then why does it automatically \n

thorny quarry
#

it doesn't

#

YOU are the one who pressed the enter key

restive nova
#

yea but thats way before

thorny quarry
#

i'm not sure why you're fighting me on this

restive nova
#

im not im just trying to understand

#

xD

thorny quarry
#

when you type "4<enter>" it goes "on the tape" and stays until scanf or fgets takes it

restive nova
#

really?

#

why does it do that

#

its like its logging my enter

#

and then getchar takes it away

#

is C the only language that does that

thorny quarry
#

no, python actually does that too

restive nova
#

damn

thorny quarry
#

you probably never dealt with bytewise i/o enough to notice

restive nova
#

so whats the difference between fgets and scanf then if the enter is always on the table

#

or on the tape

thorny quarry
#

fgets reads a line, including the <enter> at the end of it

#

scanf reads a word or number, not including anything after it (but potentially including some space before it)

restive nova
#

gotcha

#

does scanf read the <enter> from before

#

oh

#

u edited

thorny quarry
#

yep so

restive nova
#

wdym some space tho

thorny quarry
#

if you type 1<enter>2<enter>3<enter> and read it with scanf
first scanf will read just "1"
second scanf will read "<enter>2"
third will read "<enter>3"

#

"<enter>2" is the same as "2" but scanf does in fact read the <enter>

#

scanf is a bit wonky and it becomes obvious when you try to mix scanf with fgets

#

because fgets assumes you are working with lines

#

and scanf doesn't

restive nova
#

ok

#

back to the vowel situation

thorny quarry
#

sure

restive nova
#

so right now its almost done

#

it gets all the characters per line

#

so now we just use the strchr

#

aeiouy

#

thing

#

so how would i go about doing htat

#

obviously in here

#
        {



            if (strchr("aeiouy", data[x]))
            {

            // add now
            }

        }
#

int total_vowels = total_vowels+ 1;

#

is that good

thorny quarry
#

no

restive nova
#

damn

#

ok

#

lol

thorny quarry
#

int total_vowels means you're starting a new variable

#

and total_vowels = total_vowels+ 1; sounds like you're modifying an existing variable

restive nova
#

i need to declare it outside

#

right

thorny quarry
#

right

restive nova
#

total_vowels++;

thorny quarry
#

you want to do vowels = 0 each line

restive nova
#

so in the i loop

thorny quarry
#

and if ... vowels++ each character

restive nova
#

int total_vowels = 0;
in the i loop

#

total_vowels++

#

in the if statement in the x loop

thorny quarry
#

yea

restive nova
#

where would i print printf("Total Vowels: %d ", total_vowels);

#

i thought it would be outside the character inside the line

thorny quarry
#

once per line, after you've finished counting the vowels

#

therefore in the "i" loop and after the "x" loop

restive nova
#

ok

#

it worked

tardy zealotBOT
#
#include <stdio.h>
#include <stdlib.h>

int main() {
  int number_of_entries;

  char data[200] = {};
  printf("How many lines  will you have? ");
  scanf("%d", &number_of_entries);

  printf("Enter your data: ");
  getchar();

  for (int i = 0; i < number_of_entries; i++) {
    fgets(data, 200, stdin);
    int total_letters = strlen(data);
    int total_vowels = 0;

    printf("Total Numbers: %d ", total_letters);

    for (int x = 0; x < total_letters; x++) {
      if (strchr("aeiouy", data[x])) {
        total_vowels++;
      }
    }

    printf("Total Vowels: %d ", total_vowels);
  }
  return 0;
}

joeyy
restive nova
#

how do i make it wait until all the lines are stated

#

before giving me the total vowels

#

rn it says it after each line

#

i just want it to say the total vowels at the end

#

per line

#

like 2 4 5 2

thorny quarry
#

you would probably need to store it in an array instead of printing it right away

restive nova
#

because then it would add them all

#

im gonna try the array

#

myself

#

ill let you know how it goes

thorny quarry
#

ok, good luck

restive nova
#

thanks

thorny quarry
#

is this a task from the website?

restive nova
#

yea

#

its like a problem solving website

#

okay let me ask you because im stuck on a part

thorny quarry
#

i'm looking at the task and it doesn't actually say that you have to wait until the end to print the answer

restive nova
#

input data:
4
abracadabra
pear tree
o a kak ushakov lil vo kashu kakao
my pyx

answer:
5 4 13 2

#

this is what they want

#

step1: int vowels[number_of_entries] = {}; this goes outside both loops

#

step 2; this goes inside the x loop

#

vowels[i] + 1;

#

no?

thorny quarry
restive nova
#

i thought so hard onn that part

#

lol

#

because im taking the ith line

#

and adding one to it

#

no?

thorny quarry
#

did you mean vowels[i] += 1

#

otherwise vowels[i] + 1; is just 0 + 1;

restive nova
#

i want to take the number of vowels in the ith slot and add 1

#

oh right

thorny quarry
restive nova
#

+= is the same as vowels[i] = vowlels[i] + 1

restive nova
#

okay

#

step 3

#

this is where im confused

#

how do i print the whole array

#

at once

#

printf("Total Vowels: %d ", vowels[???]);

#

what does in there

#

g

thorny quarry
#

for (int i = 0; i < number_of_entries; i++) printf("Total Vowels: %d ", vowels[i]);

restive nova
#

it goes in the i loop?

thorny quarry
#

nooo

#

give it its own loop

#

but... i don't think you are supposed to say Total Vowels : 5 Total Vowels : 4 Total Vowels : 13 Total Vowels : 2

restive nova
#

ik

#

just %d

#

but im confused

#

on making its own loop

#

wouldn't that just print it more than once

#

oh

#

im dumb

#

thats what we want

#

we want it to print the whole thing

#

so this loop will print every slot in the array

#

ur so smart

#

1 issue

#
    int vowels[number_of_entries] = {};
#

it says numbers_of_entries

#

isn't initialized

#

for the vowels part

#

how would it not be initiliazed

#

if it gets the answer right there

#

in the circle

#

๐Ÿ˜•

thorny quarry
restive nova
#

yea

#

but why can't it just wing it

#

and hope it doesn't?

thorny quarry
restive nova
#

lol

#

so what should i do

#

u think

#

just put like 20

#

or 100

#

or something

#

i mean it doesn't really matter

#

i just thought it would be cool to match the size exactly

thorny quarry
#

the "right" thing to do is actually test whether scanf succeeds

#

but if it isn't going to fail then you can just get away with putting 1

restive nova
#

if i put 1 then wouldn't it stay at 1

#

and then nothing else would save?

thorny quarry
#

no, it won't stay at 1

#

not if scanf succeeds

restive nova
#

so change it from

#

int vowels[number_of_entries] = {};

#

to

#

int vowels[1] = {};

thorny quarry
#

no

restive nova
#

oh

#

i see

#

int number_of_entries = 1;

thorny quarry
#

yeah, so that it's initialised

restive nova
#

ah

#

lets see if it works

#

๐Ÿ™‚

#

wait same thing

#

i even did 10

#

@thorny quarry do you know why

#

same error

#

also what IDE do you use

#

im using code blocks rn

#

tried VSC but it was being weird

thorny quarry
#

i don't use an ide gigachad

restive nova
#

what do u use

thorny quarry
restive nova
#

int vowels[number_of_entries] = {};

#

this line

thorny quarry
restive nova
#

ah

#

code block is chill

#

im prob gonna keep using it

restive nova
#

square

thorny quarry
#

those two lines should not produce that error

restive nova
#

thats what im saying

thorny quarry
#

are there any other lines in the program?

restive nova
#
#include <stdlib.h>

int main()
{

    int number_of_entries = 1;
    int vowels[number_of_entries] = {};



    char data[200] = {};
    printf("How many lines  will you have? ");
    scanf("%d", &number_of_entries);

    printf("Enter your data: ");
    getchar();



    for (int i = 0; i < number_of_entries; i++)
    {
        fgets(data, 200, stdin);
        int total_letters = strlen(data);
        for (int x = 0; x < total_letters; x++)
        {



            if (strchr("aeiouy", data[x]))
            {

                vowels[i] += 1;
            }

        }



    }

    for (int y = 0; y < number_of_entries; y++)
    {

        printf("%d ", vowels[y]);


    }


    return 0;
}
#

thats the whole thing

#

;format ```#include <stdio.h>
#include <stdlib.h>

int main()
{

int number_of_entries = 1;
int vowels[number_of_entries] = {};



char data[200] = {};
printf("How many lines  will you have? ");
scanf("%d", &number_of_entries);

printf("Enter your data: ");
getchar();



for (int i = 0; i < number_of_entries; i++)
{
    fgets(data, 200, stdin);
    int total_letters = strlen(data);
    for (int x = 0; x < total_letters; x++)
    {



        if (strchr("aeiouy", data[x]))
        {

            vowels[i] += 1;
        }

    }



}

for (int y = 0; y < number_of_entries; y++)
{

    printf("%d ", vowels[y]);


}


return 0;

}

stuck orchidBOT
# restive nova ;format ```#include <stdio.h> #include <stdlib.h> int main() { int number_...
#include <stdio.h>
#include <stdlib.h>

int main()
{

    int number_of_entries = 1;
    int vowels[number_of_entries] = {};

    char data[200] = {};
    printf("How many lines  will you have? ");
    scanf("%d", &number_of_entries);

    printf("Enter your data: ");
    getchar();

    for (int i = 0; i < number_of_entries; i++) {
	fgets(data, 200, stdin);
	int total_letters = strlen(data);
	for (int x = 0; x < total_letters; x++) {

	    if (strchr("aeiouy", data[x])) {

		vowels[i] += 1;
	    }
	}
    }

    for (int y = 0; y < number_of_entries; y++) {

	printf("%d ", vowels[y]);
    }

    return 0;
}

Powered by godbolt.org

restive nova
#

;compile

stuck orchidBOT
#
Critical error:

You must attach a code-block containing code to your message or quote a message that has one.

restive nova
#

;compile C ```#include <stdio.h>
#include <stdlib.h>

int main()
{

int number_of_entries = 1;
int vowels[number_of_entries] = {};



char data[200] = {};
printf("How many lines  will you have? ");
scanf("%d", &number_of_entries);

printf("Enter your data: ");
getchar();



for (int i = 0; i < number_of_entries; i++)
{
    fgets(data, 200, stdin);
    int total_letters = strlen(data);
    for (int x = 0; x < total_letters; x++)
    {



        if (strchr("aeiouy", data[x]))
        {

            vowels[i] += 1;
        }

    }



}

for (int y = 0; y < number_of_entries; y++)
{

    printf("%d ", vowels[y]);


}


return 0;

}

stuck orchidBOT
#
Program Output
How many lines  will you have? Enter your data: 0
Compiler Output
<source>: In function 'main':
<source>:24:29: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
   24 |         int total_letters = strlen(data);
      |                             ^~~~~~
<source>:3:1: note: include '<string.h>' or provide a declaration of 'strlen'
    2 | #include <stdlib.h>
  +++ |+#include <string.h>
    3 | 
<source>:24:29: warning: incompatible implicit declaration of built-in function 'strlen' [-Wbuiltin-declaration-mismatch]
   24 |         int total_letters = strlen(data);
      |                             ^~~~~~
<source>:24:29: note: include '<string.h>' or provide a declaration of 'strlen'
<source>:30:17: warning: implicit declaration of function 'strchr' [-Wimplicit-function-declaration]
   30 |             if (strchr("aeiouy", data[x]))
      |                 ^~~~~~
<source>:30:17: note: include '<string.h>' or provide a declaration of 'strchr'
<source>:30:17: warning: incompatible implicit declaration of built-in f
restive nova
#

;help

stuck orchidBOT
#
Commands

For help with a specific command, type ;help <command>

Struggling? Check out our wiki

invite

Grabs the bot's invite link

compile

Compiles a script

compilers

Displays the compilers for the specified language

languages

Displays all supported languages

asm

Outputs the assembly for the input code

botinfo

Displays information about the bot

cpp
 See ;help cpp for more info ```
format

Formats code using a code formatter (i.e. clang-format or rustfmt)

formats

Displays all formatting options & styles

restive nova
#

;help compile

stuck orchidBOT
#
Compile command

Sends a compilation request

Example

;compile c++
```
#include <iostream>

int main() {
std::cout << "Hello, world";
}
```

restive nova
#

how do you include an input

#

;compile c 5```#include <stdio.h>
#include <stdlib.h>

int main()
{

int number_of_entries = 1;
int vowels[number_of_entries] = {};



char data[200] = {};
printf("How many lines  will you have? ");
scanf("%d", &number_of_entries);

printf("Enter your data: ");
getchar();



for (int i = 0; i < number_of_entries; i++)
{
    fgets(data, 200, stdin);
    int total_letters = strlen(data);
    for (int x = 0; x < total_letters; x++)
    {



        if (strchr("aeiouy", data[x]))
        {

            vowels[i] += 1;
        }

    }



}

for (int y = 0; y < number_of_entries; y++)
{

    printf("%d ", vowels[y]);


}


return 0;

}

stuck orchidBOT
#
Compiler Output
<source>: In function 'main':
<source>:24:29: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
   24 |         int total_letters = strlen(data);
      |                             ^~~~~~
<source>:3:1: note: include '<string.h>' or provide a declaration of 'strlen'
    2 | #include <stdlib.h>
  +++ |+#include <string.h>
    3 | 
<source>:24:29: warning: incompatible implicit declaration of built-in function 'strlen' [-Wbuiltin-declaration-mismatch]
   24 |         int total_letters = strlen(data);
      |                             ^~~~~~
<source>:24:29: note: include '<string.h>' or provide a declaration of 'strlen'
<source>:30:17: warning: implicit declaration of function 'strchr' [-Wimplicit-function-declaration]
   30 |             if (strchr("aeiouy", data[x]))
      |                 ^~~~~~
<source>:30:17: note: include '<string.h>' or provide a declaration of 'strchr'
<source>:30:17: warning: incompatible implicit declaration of built-in f
tardy zealotBOT
#

;compile c 5```cpp
#include <stdio.h>
#include <stdlib.h>

int main() {
int number_of_entries = 1;
int vowels[number_of_entries] = {};

char data[200] = {};
printf("How many lines will you have? ");
scanf("%d", &number_of_entries);

printf("Enter your data: ");
getchar();

for (int i = 0; i < number_of_entries; i++) {
fgets(data, 200, stdin);
int total_letters = strlen(data);
for (int x = 0; x < total_letters; x++) {
if (strchr("aeiouy", data[x])) {
vowels[i] += 1;
}
}
}

for (int y = 0; y < number_of_entries; y++) {
printf("%d ", vowels[y]);
}

return 0;
}

joeyy
restive nova
#

try compile C 5 then 5 lines

#

does it error on ur compiler

#

or nah

thorny quarry
#

why did you move int vowels[number_of_entries] = {}; before scanf

restive nova
#

did i

#

whoops

#

still the same error though

#

/format

stuck orchidBOT
#

Hello! I can compile code for you. To compile code, first post a code block containing code, right click the message, go to the Apps dropdown, and select the Compile option!

If you are unfamiliar with Markdown, codeblocks can be created by formatting your message as the following.
```
<code>
```

thorny quarry
#

the error i get is "variable length array cannot be initialised"

restive nova
#

hmm

#

what does that mean

thorny quarry
#

it means you can have
int vowels[number_of_entries];
or
int vowels[100] = {0};
but not
int vowels[number_of_entries] = {0};

restive nova
#

does it matter which one i use

#

from the top 2

thorny quarry
#

yes, it matters

restive nova
#

i chose the first one

#

lol

thorny quarry
#

well that's bad

restive nova
#

guess how many vowels

#

i did

#

per line

#

lol

thorny quarry
#

i was going to say

#

the reason it matters

#

int vowels[number_of_entries]; will be uninitialised

restive nova
#

ah

#

int vowels[100] = {0};
is the same as
int vowels[100] = {};

#

?

#

or nah

thorny quarry
#

technically int vowels[100] = {}; is not allowed.

restive nova
thorny quarry
#

they are the same, except int vowels[100] = {}; won't work sometimes

restive nova
#

it worked

thorny quarry
#

int vowels[100] = {0}; is the same as int vowels[100] = {0,0,0,0,0,0,0,}; etc

restive nova
#

๐Ÿ™‚

restive nova
#

are you curious how other people did this problemm in C?

#
#include <string.h>
#include <math.h>

int main(void)
{
    char lineSymbols[70];
    char divider[2]=" ";
    char *istr;
    FILE *file;
    char *line;
    file = fopen("input.txt","r");
    if(file==NULL){
        puts("cannot open file");
    }
    while((line=fgets(lineSymbols,70,file))!=NULL){
        int i,count=0;
        for(i=0;i<(strlen(line));i++){
            if((*(line+i)=='a')||(*(line+i)=='o')||(*(line+i)=='u')||(*(line+i)=='i')||(*(line+i)=='e')||(*(line+i)=='y')){
                count++;
            }
        }


        printf("%i  \t",count);
        /*printf("%s \n ",line);*/
    }

            fclose(file);
        return (0);
}
#

he cheated

#

he put it in a file

#

why would he do this

#

he could of done what u did

#

lmao

#

anyways

#

time to go to sleep

#

thanks for helping me better understand this all