-4

Code:

<div class="checkbox-animated-inline">
        <input id="brands" type="checkbox" ng-model="brands" ng-click="checkBrand(brands,'brands')">
        <label for="brands">
            <span class="check"></span>
            <span class="box" style="z-index:9 !important"></span>
            <strong>brands</strong>
        </label>
    </div> 

Input:

array of brands=[Maytag,Panda,Samsung,Whirlpool];

Required output:

<div class="checkbox-animated-inline">
        <input id="Maytag" type="checkbox" ng-model="Maytag" ng-click="checkBrand(Maytag,'Maytag')">
        <label for="Maytag">
            <span class="check"></span>
            <span class="box" style="z-index:9 !important"></span>
            <strong>Maytag</strong>
        </label>
    </div>
    <div class="checkbox-animated-inline">
        <input id="Panda" type="checkbox" ng-model="Panda" ng-click="checkBrand(Panda,'Panda')">
        <label for="Panda">
            <span class="check"></span>
            <span class="box" style="z-index:9 !important"></span>
            <strong>Panda</strong>
        </label>
    </div>
    <div class="checkbox-animated-inline">
        <input id="Samsung" type="checkbox" ng-model="Samsung" ng-click="checkBrand(Samsung,'Samsung')">
        <label for="Samsung">
            <span class="check"></span>
            <span class="box" style="z-index:9 !important"></span>
            <strong>Samsung</strong>
        </label>
    </div>
    <div class="checkbox-animated-inline">
        <input id="Whirlpool" type="checkbox" ng-model="Whirlpool" ng-click="checkBrand(Whirlpool,'Whirlpool')">
        <label for="Whirlpool">
            <span class="check"></span>
            <span class="box" style="z-index:9 !important"></span>
            <strong>Whirlpool</strong>
        </label>
    </div>

Tried code :

#include <stdio.h>
#include <strings.h>
typedef char * string;

int main(void)
{
  string strs[5];  // Make 5 strings
  int i;

  strs[0] = "Maytag";
  strs[1] = "Panda";
  strs[2] = "Samsung";
  strs[3] = "Whirlpool";

  for(i = 0;i < 4;++i)
    printf("<div class="checkbox-animated-inline">
        <input id="%s" type="checkbox" ng-model="%s" ng-click="checkBrand(%s,'%s')">
        <label for="%s">
            <span class="check"></span>
            <span class="box" style="z-index:9 !important"></span>
            <strong>%s</strong>
        </label>
    </div> ",strs[i]);

  return 0;
}

I tried the above code but it is showing me a lot of errors. My question is, how can I replace the brand with the list of brands and display the output using loop or by using a function? If there are any tools that can replace the word with list of elements from the array.

Rorschach
  • 31,301
  • 5
  • 78
  • 129
raj
  • 3
  • 3
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Jun 10 '18 at 20:35
  • @halfer added the tried code to question,sorry for missing it.And thanks for your quick response – raj Jun 10 '18 at 20:50
  • @jenesaisquoi can u please solve this code and give me exact working result. I am trying it from almost a couple of days.Tired of trying it again.Pls help me with it – raj Jun 10 '18 at 20:54
  • #include #include typedef char * string; int main(void) { string strs[5]; // Make 5 strings int i; strs[0] = "Maytag"; strs[1] = "Panda"; strs[2] = "Samsung"; strs[3] = "Whirlpool"; for(i = 0;i < 4;++i) printf("
    \n",strs[i]); return 0; }
    – raj Jun 10 '18 at 21:07
  • i am still getting the errors – raj Jun 10 '18 at 21:08
  • @raj: please delete that code sample in a comment, and update your question, using the formatting tools provided. Additionally, please do really make as much of an effort as you can if someone gives you some advice - a reply of "do it for me plz" is a recipe for downvotes here. – halfer Jun 10 '18 at 21:17
  • My advice was helpful, but it is up to you whether you wish to be helped. It is worth your knowing that we get a lot of requests for free work here (of which yours may still be one) so people's reticence to offer boundless amounts of gratis labour is very well founded. I have now added a downvote for your comment, and have reported your comment as abusive (which is permanently recorded on your account for moderators to see). Please do not dig a hole for yourself - Stack Overflow is an excellent resource if you use it well. – halfer Jun 10 '18 at 21:36
  • @halfer wow halfer, thanks for helping me to block my account.Hope moderators see what wrong did i say and judge. – raj Jun 10 '18 at 21:42
  • I am afraid you brought that squarely upon yourself, Raj. You cannot engage in abusive language and then claim the consequences are someone else's fault. – halfer Jun 10 '18 at 21:45
  • @halfer, and by the way dnt ever call anyones work a free work .Well i can hire developers(may be better than you for so called free work ) – raj Jun 10 '18 at 21:46
  • @halfer, i wasnt abusive,i just said meaningless suggestions,coz i was pissed off with the code and you guys were not guiding me in the easy manner. – raj Jun 10 '18 at 21:47
  • I am not in the least bit competitive, so your developers can be as talented as you like. Indeed, you have exactly the right idea: if you want people to do work for you, without any effort on your part, then you should hire them. I frequently suggest to people here that they engage the services of a freelancer (and I can suggest some hourly-rate freelancer sites too). – halfer Jun 10 '18 at 21:47
  • 1
    @halfer lol, it was nice fighting with you. Sorry if i was too much abusive. Thanks for the help. Stackoverflow has always helped me. but this time i didnt show patience . Thanks again – raj Jun 10 '18 at 21:51

1 Answers1

1

You need to escape the quotes.

A string in C which has " as its part may be written as

char str[]="quote\"quote\"";
printf("%s", str);

This would print quote"quote". " which are not escaped denote the bounds of the string.

Also, the %s format specifier is used 6 times in the format string of printf() but only one address is given. You must provide all six addresses otherwise format string attacks are possible.

And see Is it a good idea to typedef pointers and What are the valid signatures for C's main() function as well.

So, try

for(i = 0;i < 4;++i)
    printf("\n<div class=\"checkbox-animated-inline\">\n\
    <input id=\"%s\" type=\"checkbox\" ng-model=\"%s\" ng-click=\"checkBrand(%s,'%s')\">\n\
    <label for=\"%s\">\n\
        <span class=\"check\"></span>\n\
        <span class=\"box\" style=\"z-index:9 !important\"></span>\n\
        <strong>%s</strong>\n\
    </label>\n\
</div> ",strs[i], strs[i],strs[i],strs[i],strs[i],strs[i]);

Output:

<div class="checkbox-animated-inline">
        <input id="Maytag" type="checkbox" ng-model="Maytag" ng-click="checkBrand(Maytag,'Maytag')">
        <label for="Maytag">
            <span class="check"></span>
            <span class="box" style="z-index:9 !important"></span>
            <strong>Maytag</strong>
        </label>
    </div>
<div class="checkbox-animated-inline">
        <input id="Panda" type="checkbox" ng-model="Panda" ng-click="checkBrand(Panda,'Panda')">
        <label for="Panda">
            <span class="check"></span>
            <span class="box" style="z-index:9 !important"></span>
            <strong>Panda</strong>
        </label>
    </div>
<div class="checkbox-animated-inline">
        <input id="Samsung" type="checkbox" ng-model="Samsung" ng-click="checkBrand(Samsung,'Samsung')">
        <label for="Samsung">
            <span class="check"></span>
            <span class="box" style="z-index:9 !important"></span>
            <strong>Samsung</strong>
        </label>
    </div>
<div class="checkbox-animated-inline">
        <input id="Whirlpool" type="checkbox" ng-model="Whirlpool" ng-click="checkBrand(Whirlpool,'Whirlpool')">
        <label for="Whirlpool">
            <span class="check"></span>
            <span class="box" style="z-index:9 !important"></span>
            <strong>Whirlpool</strong>
        </label>
    </div>
J...S
  • 5,079
  • 1
  • 20
  • 35