N
N
Nastyuuuushka2016-07-23 20:32:02
Programming
Nastyuuuushka, 2016-07-23 20:32:02

How to port JS code to C, what am I doing wrong?

Is it possible to transfer this from JS to C?
for (var line = "#"; line.length < 7; line += "#") {
console.log(line);
Like
for(char line="#"; line.length<7; line+="#"){
printf("%d",line);
}
You need to line up something like:
#
##
###
####
#####
######
#######

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
none7, 2016-07-24
@none7

In pure C, there are no dynamic strings, only numeric variables, pointers (references), structures, and fixed size arrays. The closest to JS code, but also the most crooked, will be the following code:

char line[8];
*line = 0;
for(strcat(line, "#"); strlen(line) < 7; strcat(line, "#"))
    puts(line);

G
Governor, 2016-07-23
@Mr-Governor

char line = '#';
for (int i=1; i<=7; i++)
{
  for (int j=1; j<=i; j++)
    printf("%d", line); //Напечатать решетку
  printf("%d", "\n"); //Перевести на нов. строку
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question